@capxul/sdk 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/README.md +9 -0
- package/dist/InMemoryAuthCacheAdapter-CHYpYyk5.mjs.map +1 -1
- package/dist/{index-D1rNjmof.d.mts → index-Bs-M7EPt.d.mts} +8 -2
- package/dist/index-Bs-M7EPt.d.mts.map +1 -0
- package/dist/index.d.mts +97 -25
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +392 -148
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.d.mts +2 -2
- package/dist/ports/safe-deployment.d.mts +1 -1
- package/dist/{safe-deployment-BID2pXZN.d.mts → safe-deployment-BLXJ5Ed8.d.mts} +2 -2
- package/dist/{safe-deployment-BID2pXZN.d.mts.map → safe-deployment-BLXJ5Ed8.d.mts.map} +1 -1
- package/dist/{signer-AXnBJuAN.d.mts → signer-Rr9Y8aGi.d.mts} +2 -2
- package/dist/{signer-AXnBJuAN.d.mts.map → signer-Rr9Y8aGi.d.mts.map} +1 -1
- package/package.json +4 -4
- package/dist/index-D1rNjmof.d.mts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -376,6 +376,45 @@ function captureExceptionSync(telemetry, error, context) {
|
|
|
376
376
|
} catch {}
|
|
377
377
|
}
|
|
378
378
|
//#endregion
|
|
379
|
+
//#region src/internal/invocation-observation.ts
|
|
380
|
+
const INVOCATION_OBSERVATION = Symbol("capxul.invocation-observation");
|
|
381
|
+
const FAILURE_INVOCATION_SNAPSHOT = Symbol("capxul.failure-invocation-snapshot");
|
|
382
|
+
/** @internal Attach one immutable, non-wire invocation snapshot to an SDK-owned object. */
|
|
383
|
+
function attachInvocationObservation(target, context) {
|
|
384
|
+
const snapshot = Object.freeze(context === void 0 ? {} : { context: Object.freeze({ ...context }) });
|
|
385
|
+
Object.defineProperty(target, INVOCATION_OBSERVATION, {
|
|
386
|
+
configurable: false,
|
|
387
|
+
enumerable: false,
|
|
388
|
+
value: snapshot,
|
|
389
|
+
writable: false
|
|
390
|
+
});
|
|
391
|
+
return target;
|
|
392
|
+
}
|
|
393
|
+
/** @internal Read the snapshot without exposing its symbol or adding a wire field. */
|
|
394
|
+
function readInvocationObservation(source) {
|
|
395
|
+
if (typeof source !== "object" || source === null) return void 0;
|
|
396
|
+
return source[INVOCATION_OBSERVATION];
|
|
397
|
+
}
|
|
398
|
+
/** @internal Carry a snapshot across an SDK adapter projection without resolving again. */
|
|
399
|
+
function copyInvocationObservation(source, target) {
|
|
400
|
+
const snapshot = readInvocationObservation(source);
|
|
401
|
+
return snapshot === void 0 ? target : attachInvocationObservation(target, snapshot.context);
|
|
402
|
+
}
|
|
403
|
+
/** @internal Mark a failure envelope as already resolved at the public invocation boundary. */
|
|
404
|
+
function markFailureInvocationSnapshot(failure) {
|
|
405
|
+
Object.defineProperty(failure, FAILURE_INVOCATION_SNAPSHOT, {
|
|
406
|
+
configurable: false,
|
|
407
|
+
enumerable: false,
|
|
408
|
+
value: true,
|
|
409
|
+
writable: false
|
|
410
|
+
});
|
|
411
|
+
return failure;
|
|
412
|
+
}
|
|
413
|
+
/** @internal Distinguish public-boundary failures from direct adapter calls. */
|
|
414
|
+
function hasFailureInvocationSnapshot(failure) {
|
|
415
|
+
return typeof failure === "object" && failure !== null && failure[FAILURE_INVOCATION_SNAPSHOT] === true;
|
|
416
|
+
}
|
|
417
|
+
//#endregion
|
|
379
418
|
//#region src/client/_shared/effect-actor-bridge.ts
|
|
380
419
|
/**
|
|
381
420
|
* Bridge an Effect whose typed failure carries `{ publicError: CapxulError }`
|
|
@@ -1221,7 +1260,7 @@ function makeAccountMethods(deps) {
|
|
|
1221
1260
|
};
|
|
1222
1261
|
};
|
|
1223
1262
|
const deployMutex = /* @__PURE__ */ new Map();
|
|
1224
|
-
const deploySafeImpl = async () => {
|
|
1263
|
+
const deploySafeImpl = async (observationSource) => {
|
|
1225
1264
|
const session = await currentSession(deps.actor, deps.authCache);
|
|
1226
1265
|
if (session === null) return {
|
|
1227
1266
|
ok: false,
|
|
@@ -1249,7 +1288,8 @@ function makeAccountMethods(deps) {
|
|
|
1249
1288
|
authUserId: session.authUserId,
|
|
1250
1289
|
chainId: deps.chainId,
|
|
1251
1290
|
signer,
|
|
1252
|
-
smartAccountPort: deps.smartAccountPort
|
|
1291
|
+
smartAccountPort: deps.smartAccountPort,
|
|
1292
|
+
observationSource
|
|
1253
1293
|
}).finally(() => {
|
|
1254
1294
|
deployMutex.delete(mutexKey);
|
|
1255
1295
|
});
|
|
@@ -1373,11 +1413,11 @@ async function runBackendClaim(input) {
|
|
|
1373
1413
|
error: Errors.providerError("signer", "getAddress", cause)
|
|
1374
1414
|
};
|
|
1375
1415
|
}
|
|
1376
|
-
const claimed = await runPortEffect(input.smartAccountPort.claim({
|
|
1416
|
+
const claimed = await runPortEffect(input.smartAccountPort.claim(copyInvocationObservation(input.observationSource, {
|
|
1377
1417
|
authUserId: input.authUserId,
|
|
1378
1418
|
chainId,
|
|
1379
1419
|
signerAddress
|
|
1380
|
-
}));
|
|
1420
|
+
})));
|
|
1381
1421
|
if (!claimed.ok) return claimed;
|
|
1382
1422
|
return {
|
|
1383
1423
|
ok: true,
|
|
@@ -1652,7 +1692,7 @@ async function recoverRawDigestSigner(input) {
|
|
|
1652
1692
|
}
|
|
1653
1693
|
//#endregion
|
|
1654
1694
|
//#region package.json
|
|
1655
|
-
var version = "1.0.0-alpha.
|
|
1695
|
+
var version = "1.0.0-alpha.22";
|
|
1656
1696
|
//#endregion
|
|
1657
1697
|
//#region src/ports/auth-client.ts
|
|
1658
1698
|
var AuthClientError = class extends Data.TaggedError("AuthClientError") {};
|
|
@@ -1738,6 +1778,10 @@ const FIELD_RULES = {
|
|
|
1738
1778
|
maxLength: 128,
|
|
1739
1779
|
pattern: /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u
|
|
1740
1780
|
},
|
|
1781
|
+
journeyId: {
|
|
1782
|
+
maxLength: 128,
|
|
1783
|
+
pattern: /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u
|
|
1784
|
+
},
|
|
1741
1785
|
correlationId: {
|
|
1742
1786
|
maxLength: 128,
|
|
1743
1787
|
pattern: /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u
|
|
@@ -3011,48 +3055,10 @@ function convexCallErrorFromCapxul(operation, error) {
|
|
|
3011
3055
|
}
|
|
3012
3056
|
var ConvexCallPortTag = class extends Context.Tag("@capxul/sdk/ports/ConvexCallPort")() {};
|
|
3013
3057
|
//#endregion
|
|
3014
|
-
//#region src/internal/invocation-observation.ts
|
|
3015
|
-
const INVOCATION_OBSERVATION = Symbol("capxul.invocation-observation");
|
|
3016
|
-
const FAILURE_INVOCATION_SNAPSHOT = Symbol("capxul.failure-invocation-snapshot");
|
|
3017
|
-
/** @internal Attach one immutable, non-wire invocation snapshot to an SDK-owned object. */
|
|
3018
|
-
function attachInvocationObservation(target, context) {
|
|
3019
|
-
const snapshot = Object.freeze(context === void 0 ? {} : { context: Object.freeze({ ...context }) });
|
|
3020
|
-
Object.defineProperty(target, INVOCATION_OBSERVATION, {
|
|
3021
|
-
configurable: false,
|
|
3022
|
-
enumerable: false,
|
|
3023
|
-
value: snapshot,
|
|
3024
|
-
writable: false
|
|
3025
|
-
});
|
|
3026
|
-
return target;
|
|
3027
|
-
}
|
|
3028
|
-
/** @internal Read the snapshot without exposing its symbol or adding a wire field. */
|
|
3029
|
-
function readInvocationObservation(source) {
|
|
3030
|
-
if (typeof source !== "object" || source === null) return void 0;
|
|
3031
|
-
return source[INVOCATION_OBSERVATION];
|
|
3032
|
-
}
|
|
3033
|
-
/** @internal Carry a snapshot across an SDK adapter projection without resolving again. */
|
|
3034
|
-
function copyInvocationObservation(source, target) {
|
|
3035
|
-
const snapshot = readInvocationObservation(source);
|
|
3036
|
-
return snapshot === void 0 ? target : attachInvocationObservation(target, snapshot.context);
|
|
3037
|
-
}
|
|
3038
|
-
/** @internal Mark a failure envelope as already resolved at the public invocation boundary. */
|
|
3039
|
-
function markFailureInvocationSnapshot(failure) {
|
|
3040
|
-
Object.defineProperty(failure, FAILURE_INVOCATION_SNAPSHOT, {
|
|
3041
|
-
configurable: false,
|
|
3042
|
-
enumerable: false,
|
|
3043
|
-
value: true,
|
|
3044
|
-
writable: false
|
|
3045
|
-
});
|
|
3046
|
-
return failure;
|
|
3047
|
-
}
|
|
3048
|
-
/** @internal Distinguish public-boundary failures from direct adapter calls. */
|
|
3049
|
-
function hasFailureInvocationSnapshot(failure) {
|
|
3050
|
-
return typeof failure === "object" && failure !== null && failure[FAILURE_INVOCATION_SNAPSHOT] === true;
|
|
3051
|
-
}
|
|
3052
|
-
//#endregion
|
|
3053
3058
|
//#region src/adapters/convex-call/ConvexCallAdapter.ts
|
|
3054
3059
|
/** Exact floor-first allowlist; every additional handler must migrate its validator first. */
|
|
3055
|
-
const OBSERVED_CONVEX_ACTIONS = new Set(["subAccount/actions:transfer"]);
|
|
3060
|
+
const OBSERVED_CONVEX_ACTIONS = new Set(["subAccount/actions:transfer", "smartAccount/actions:claim"]);
|
|
3061
|
+
const OBSERVED_CONVEX_MUTATIONS = new Set(["org/lifecycle:startOrResume", "org/lifecycle:retry"]);
|
|
3056
3062
|
var ConvexCallAdapter = class {
|
|
3057
3063
|
#client;
|
|
3058
3064
|
#tokenProvider;
|
|
@@ -3075,20 +3081,21 @@ var ConvexCallAdapter = class {
|
|
|
3075
3081
|
});
|
|
3076
3082
|
}
|
|
3077
3083
|
mutation(fn, args) {
|
|
3084
|
+
const path = getFunctionName(fn);
|
|
3078
3085
|
return Effect.tryPromise({
|
|
3079
|
-
try: () => this.#client.mutation(fn, args),
|
|
3080
|
-
catch: (cause) => mapToConvexCallError(
|
|
3086
|
+
try: () => this.#client.mutation(fn, this.#observedArgs(OBSERVED_CONVEX_MUTATIONS, path, args)),
|
|
3087
|
+
catch: (cause) => mapToConvexCallError(path, cause)
|
|
3081
3088
|
});
|
|
3082
3089
|
}
|
|
3083
3090
|
action(fn, args) {
|
|
3084
3091
|
const path = getFunctionName(fn);
|
|
3085
3092
|
return Effect.tryPromise({
|
|
3086
|
-
try: () => this.#client.action(fn, this.#
|
|
3093
|
+
try: () => this.#client.action(fn, this.#observedArgs(OBSERVED_CONVEX_ACTIONS, path, args)),
|
|
3087
3094
|
catch: (cause) => mapToConvexCallError(path, cause)
|
|
3088
3095
|
});
|
|
3089
3096
|
}
|
|
3090
|
-
#
|
|
3091
|
-
if (!
|
|
3097
|
+
#observedArgs(allowlist, path, args) {
|
|
3098
|
+
if (!allowlist.has(path)) return args;
|
|
3092
3099
|
let hostContext;
|
|
3093
3100
|
const invocationSnapshot = readInvocationObservation(args);
|
|
3094
3101
|
if (invocationSnapshot !== void 0) hostContext = invocationSnapshot.context;
|
|
@@ -3678,6 +3685,10 @@ function brandProfile(raw) {
|
|
|
3678
3685
|
email: toEmail(raw.email),
|
|
3679
3686
|
displayName: raw.displayName,
|
|
3680
3687
|
country: raw.country === null ? null : toCountryCode(raw.country),
|
|
3688
|
+
onboarded: raw.onboarded ?? false,
|
|
3689
|
+
withdrawalAddress: raw.withdrawalAddress === null || raw.withdrawalAddress === void 0 ? null : toAddress(raw.withdrawalAddress),
|
|
3690
|
+
username: raw.username ?? null,
|
|
3691
|
+
imageUrl: raw.imageUrl ?? null,
|
|
3681
3692
|
kycTier: toKycTier(raw.kycTier),
|
|
3682
3693
|
createdAt: toEpochMs(raw.createdAt),
|
|
3683
3694
|
updatedAt: toEpochMs(raw.updatedAt)
|
|
@@ -3937,11 +3948,11 @@ var ConvexSmartAccountAdapter = class {
|
|
|
3937
3948
|
})), Effect.catchAllDefect((cause) => Effect.fail(smartAccountErrorFromUnknown("confirmDeployment", cause))));
|
|
3938
3949
|
}
|
|
3939
3950
|
claim(input) {
|
|
3940
|
-
return this.#convex.action(this.#fns.claim, {
|
|
3951
|
+
return this.#convex.action(this.#fns.claim, copyInvocationObservation(input, {
|
|
3941
3952
|
chainId: wireChainId(input.chainId),
|
|
3942
3953
|
signerAddress: input.signerAddress,
|
|
3943
3954
|
...input.telemetryRunId === void 0 ? {} : { telemetryRunId: input.telemetryRunId }
|
|
3944
|
-
}).pipe(Effect.mapError((error) => smartAccountErrorFromCapxul("claim", error.publicError, error)), Effect.flatMap((row) => Effect.try({
|
|
3955
|
+
})).pipe(Effect.mapError((error) => smartAccountErrorFromCapxul("claim", error.publicError, error)), Effect.flatMap((row) => Effect.try({
|
|
3945
3956
|
try: () => brandProvisionedSmartAccount(input.authUserId, row),
|
|
3946
3957
|
catch: (cause) => smartAccountErrorFromUnknown("claim", cause)
|
|
3947
3958
|
})), Effect.catchAllDefect((cause) => Effect.fail(smartAccountErrorFromUnknown("claim", cause))));
|
|
@@ -4007,7 +4018,10 @@ function brandOrgView(wire, treasury, viewerRole) {
|
|
|
4007
4018
|
handle: wire.slug,
|
|
4008
4019
|
safeAddress: toAddress(wire.safeAddress.toLowerCase()),
|
|
4009
4020
|
role: viewerRole,
|
|
4010
|
-
treasury
|
|
4021
|
+
treasury,
|
|
4022
|
+
bio: wire.bio ?? null,
|
|
4023
|
+
size: wire.size ?? null,
|
|
4024
|
+
logoUrl: wire.logoUrl ?? null
|
|
4011
4025
|
};
|
|
4012
4026
|
}
|
|
4013
4027
|
/**
|
|
@@ -4203,14 +4217,19 @@ const DEFAULT_FUNCTIONS$1 = {
|
|
|
4203
4217
|
var ConvexOrganizationSetupAdapter = class {
|
|
4204
4218
|
#convex;
|
|
4205
4219
|
#signer;
|
|
4220
|
+
#chainId;
|
|
4206
4221
|
#fns;
|
|
4207
4222
|
constructor(input) {
|
|
4208
4223
|
this.#convex = input.convex;
|
|
4209
4224
|
this.#signer = input.signer;
|
|
4225
|
+
this.#chainId = input.chainId;
|
|
4210
4226
|
this.#fns = input.functions ?? DEFAULT_FUNCTIONS$1;
|
|
4211
4227
|
}
|
|
4212
4228
|
async startOrResume(input) {
|
|
4213
|
-
const result = await runCall("startOrResume", this.#convex.mutation(this.#fns.startOrResume, input
|
|
4229
|
+
const result = await runCall("startOrResume", this.#convex.mutation(this.#fns.startOrResume, copyInvocationObservation(input, {
|
|
4230
|
+
...input,
|
|
4231
|
+
chainId: this.#chainId
|
|
4232
|
+
})));
|
|
4214
4233
|
if (!result.ok) return result;
|
|
4215
4234
|
const lifecycle = parseLifecycle("startOrResume", result.value.lifecycle);
|
|
4216
4235
|
if (!lifecycle.ok) return lifecycle;
|
|
@@ -4226,17 +4245,17 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
4226
4245
|
};
|
|
4227
4246
|
}
|
|
4228
4247
|
prepareFounderAccount(input) {
|
|
4229
|
-
return this.#lifecycleAction("prepareFounderAccount", input, () => this.#convex.action(this.#fns.prepareFounderAccount, { orgId: input.orgId }));
|
|
4248
|
+
return this.#lifecycleAction("prepareFounderAccount", input, () => this.#convex.action(this.#fns.prepareFounderAccount, copyInvocationObservation(input, { orgId: input.orgId })));
|
|
4230
4249
|
}
|
|
4231
4250
|
async authorizeAndSubmitBootstrap(input) {
|
|
4232
4251
|
const cancelled = cancellation(input.signal);
|
|
4233
4252
|
if (cancelled !== void 0) return cancelled;
|
|
4234
4253
|
const signerAddress = await signerResult("getAddress", () => this.#signer.getAddress());
|
|
4235
4254
|
if (!signerAddress.ok) return signerAddress;
|
|
4236
|
-
const prepared = await runCall("prepareBootstrap", this.#convex.action(this.#fns.prepareBootstrap, {
|
|
4255
|
+
const prepared = await runCall("prepareBootstrap", this.#convex.action(this.#fns.prepareBootstrap, copyInvocationObservation(input, {
|
|
4237
4256
|
orgId: input.orgId,
|
|
4238
4257
|
signerAddress: signerAddress.value
|
|
4239
|
-
}));
|
|
4258
|
+
})));
|
|
4240
4259
|
if (!prepared.ok) return prepared;
|
|
4241
4260
|
const authority = validatePreparedAuthorities(prepared.value, signerAddress.value);
|
|
4242
4261
|
if (!authority.ok) return authority;
|
|
@@ -4246,25 +4265,25 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
4246
4265
|
if (!signature.ok) return signature;
|
|
4247
4266
|
const cancelledAfterSign = cancellation(input.signal);
|
|
4248
4267
|
if (cancelledAfterSign !== void 0) return cancelledAfterSign;
|
|
4249
|
-
const submitted = await runCall("submitBootstrap", this.#convex.action(this.#fns.submitBootstrap, {
|
|
4268
|
+
const submitted = await runCall("submitBootstrap", this.#convex.action(this.#fns.submitBootstrap, copyInvocationObservation(input, {
|
|
4250
4269
|
orgId: input.orgId,
|
|
4251
4270
|
signerAddress: signerAddress.value,
|
|
4252
4271
|
signature: signature.value,
|
|
4253
4272
|
userOp: prepared.value.userOp
|
|
4254
|
-
}));
|
|
4273
|
+
})));
|
|
4255
4274
|
if (!submitted.ok) return submitted;
|
|
4256
4275
|
return parseLifecycle("submitBootstrap", submitted.value);
|
|
4257
4276
|
}
|
|
4258
4277
|
resumeSubmittedBootstrap(input) {
|
|
4259
|
-
return this.#lifecycleAction("resumeBootstrapSubmission", input, () => this.#convex.action(this.#fns.resumeBootstrapSubmission, { orgId: input.orgId }));
|
|
4278
|
+
return this.#lifecycleAction("resumeBootstrapSubmission", input, () => this.#convex.action(this.#fns.resumeBootstrapSubmission, copyInvocationObservation(input, { orgId: input.orgId })));
|
|
4260
4279
|
}
|
|
4261
4280
|
confirmSubmittedBootstrap(input) {
|
|
4262
|
-
return this.#lifecycleAction("confirmBootstrap", input, () => this.#convex.action(this.#fns.confirmBootstrap, { orgId: input.orgId }));
|
|
4281
|
+
return this.#lifecycleAction("confirmBootstrap", input, () => this.#convex.action(this.#fns.confirmBootstrap, copyInvocationObservation(input, { orgId: input.orgId })));
|
|
4263
4282
|
}
|
|
4264
4283
|
async recordFailure(input) {
|
|
4265
4284
|
const errorProvider = input.error.details?.provider;
|
|
4266
4285
|
const errorOperation = input.error.details?.operation;
|
|
4267
|
-
const result = await runCall("recordFailure", this.#convex.mutation(this.#fns.recordFailure, {
|
|
4286
|
+
const result = await runCall("recordFailure", this.#convex.mutation(this.#fns.recordFailure, copyInvocationObservation(input, {
|
|
4268
4287
|
orgId: input.orgId,
|
|
4269
4288
|
errorCode: input.error.code,
|
|
4270
4289
|
...typeof errorProvider === "string" && typeof errorOperation === "string" ? {
|
|
@@ -4272,7 +4291,7 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
4272
4291
|
errorOperation
|
|
4273
4292
|
} : {},
|
|
4274
4293
|
retryable: input.retryable
|
|
4275
|
-
}));
|
|
4294
|
+
})));
|
|
4276
4295
|
return result.ok ? parseLifecycle("recordFailure", result.value) : result;
|
|
4277
4296
|
}
|
|
4278
4297
|
async loadLifecycle(input) {
|
|
@@ -4290,7 +4309,7 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
4290
4309
|
const reset = resetSignerSession(this.#signer);
|
|
4291
4310
|
if (!reset.ok) return reset;
|
|
4292
4311
|
}
|
|
4293
|
-
const result = await runCall("retry", this.#convex.mutation(this.#fns.retry, { orgId: input.orgId }));
|
|
4312
|
+
const result = await runCall("retry", this.#convex.mutation(this.#fns.retry, copyInvocationObservation(input, { orgId: input.orgId })));
|
|
4294
4313
|
if (!result.ok) return result;
|
|
4295
4314
|
return parseLifecycle("retry", result.value);
|
|
4296
4315
|
}
|
|
@@ -4475,6 +4494,7 @@ const PayeeIdTelemetrySchema = Schema.String.pipe(Schema.filter((value) => PAYEE
|
|
|
4475
4494
|
const DocumentHashSchema = Schema.String.pipe(Schema.filter((value) => BYTES32_RE.test(value), { message: () => "must be 0x + 64 hex chars" }));
|
|
4476
4495
|
const TelemetryEnvelopeProps = {
|
|
4477
4496
|
capxul_e2e_run_id: OptionalString,
|
|
4497
|
+
journeyId: OptionalString,
|
|
4478
4498
|
correlationId: OptionalString,
|
|
4479
4499
|
capxulEnv: OptionalString,
|
|
4480
4500
|
sdkVersion: OptionalString,
|
|
@@ -4606,6 +4626,46 @@ const TransferFailedProps = Schema.Struct({
|
|
|
4606
4626
|
const ORG_ID_TELEMETRY_RE = /^org_[0-9A-Za-z]+$/;
|
|
4607
4627
|
const OrgIdTelemetrySchema = Schema.String.pipe(Schema.filter((value) => ORG_ID_TELEMETRY_RE.test(value), { message: () => "must be org_ plus an alphanumeric id" }));
|
|
4608
4628
|
const OptionalOrgId = Schema.optional(OrgIdTelemetrySchema);
|
|
4629
|
+
const AttemptNumberSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value > 0, { message: () => "must be a positive safe integer" }));
|
|
4630
|
+
const OnboardingStageSchema = Schema.Literal("profile", "accountProvisioning", "accountClaim", "preparingFounderAccount", "awaitingFounderAuthorization", "submittingBootstrap", "confirmingBootstrap");
|
|
4631
|
+
const MemberActivationStartedProps = Schema.Struct({
|
|
4632
|
+
$insert_id: Schema.String,
|
|
4633
|
+
producer: Schema.Literal("server")
|
|
4634
|
+
});
|
|
4635
|
+
const MemberActivationReadyProps = Schema.Struct({
|
|
4636
|
+
$insert_id: Schema.String,
|
|
4637
|
+
duration_ms: DurationMsSchema,
|
|
4638
|
+
producer: Schema.Literal("server")
|
|
4639
|
+
});
|
|
4640
|
+
const MemberActivationFailedProps = Schema.Struct({
|
|
4641
|
+
$insert_id: Schema.String,
|
|
4642
|
+
stage: OnboardingStageSchema,
|
|
4643
|
+
error_code: Schema.String,
|
|
4644
|
+
retryable: Schema.Boolean,
|
|
4645
|
+
producer: Schema.Literal("server")
|
|
4646
|
+
});
|
|
4647
|
+
const OrganizationCreationStartedProps = Schema.Struct({
|
|
4648
|
+
$insert_id: Schema.String,
|
|
4649
|
+
organization_id: OrgIdTelemetrySchema,
|
|
4650
|
+
attempt_number: AttemptNumberSchema,
|
|
4651
|
+
producer: Schema.Literal("server")
|
|
4652
|
+
});
|
|
4653
|
+
const OrganizationCreationReadyProps = Schema.Struct({
|
|
4654
|
+
$insert_id: Schema.String,
|
|
4655
|
+
organization_id: OrgIdTelemetrySchema,
|
|
4656
|
+
attempt_number: AttemptNumberSchema,
|
|
4657
|
+
duration_ms: DurationMsSchema,
|
|
4658
|
+
producer: Schema.Literal("server")
|
|
4659
|
+
});
|
|
4660
|
+
const OrganizationCreationFailedProps = Schema.Struct({
|
|
4661
|
+
$insert_id: Schema.String,
|
|
4662
|
+
organization_id: OrgIdTelemetrySchema,
|
|
4663
|
+
attempt_number: AttemptNumberSchema,
|
|
4664
|
+
stage: OnboardingStageSchema,
|
|
4665
|
+
error_code: Schema.String,
|
|
4666
|
+
retryable: Schema.Boolean,
|
|
4667
|
+
producer: Schema.Literal("server")
|
|
4668
|
+
});
|
|
4609
4669
|
const OrgCreateStartedProps = Schema.Struct({
|
|
4610
4670
|
...TelemetryEnvelopeProps,
|
|
4611
4671
|
org_id: OptionalOrgId,
|
|
@@ -4767,6 +4827,30 @@ Schema.Struct({
|
|
|
4767
4827
|
name: Schema.Literal("bootstrap_failed"),
|
|
4768
4828
|
props: Schema.optional(BootstrapFailedProps)
|
|
4769
4829
|
});
|
|
4830
|
+
Schema.Struct({
|
|
4831
|
+
name: Schema.Literal("member_activation_started"),
|
|
4832
|
+
props: MemberActivationStartedProps
|
|
4833
|
+
});
|
|
4834
|
+
Schema.Struct({
|
|
4835
|
+
name: Schema.Literal("member_activation_ready"),
|
|
4836
|
+
props: MemberActivationReadyProps
|
|
4837
|
+
});
|
|
4838
|
+
Schema.Struct({
|
|
4839
|
+
name: Schema.Literal("member_activation_failed"),
|
|
4840
|
+
props: MemberActivationFailedProps
|
|
4841
|
+
});
|
|
4842
|
+
Schema.Struct({
|
|
4843
|
+
name: Schema.Literal("organization_creation_started"),
|
|
4844
|
+
props: OrganizationCreationStartedProps
|
|
4845
|
+
});
|
|
4846
|
+
Schema.Struct({
|
|
4847
|
+
name: Schema.Literal("organization_creation_ready"),
|
|
4848
|
+
props: OrganizationCreationReadyProps
|
|
4849
|
+
});
|
|
4850
|
+
Schema.Struct({
|
|
4851
|
+
name: Schema.Literal("organization_creation_failed"),
|
|
4852
|
+
props: OrganizationCreationFailedProps
|
|
4853
|
+
});
|
|
4770
4854
|
Schema.Struct({
|
|
4771
4855
|
name: Schema.Literal("account_balance_read"),
|
|
4772
4856
|
props: Schema.optional(AccountBalanceReadProps)
|
|
@@ -6455,14 +6539,29 @@ const loadIdentityProgram = Effect.gen(function* () {
|
|
|
6455
6539
|
});
|
|
6456
6540
|
//#endregion
|
|
6457
6541
|
//#region src/client/identity.ts
|
|
6542
|
+
const usernameAvailableQuery = makeFunctionReference("identity/queries:usernameAvailable");
|
|
6458
6543
|
function makeIdentityMethods(deps) {
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6544
|
+
const convexCall = deps.convexCall;
|
|
6545
|
+
return {
|
|
6546
|
+
async loadCurrent(options) {
|
|
6547
|
+
if (options?.signal?.aborted) return {
|
|
6548
|
+
ok: false,
|
|
6549
|
+
error: Errors.cancelled({ operation: "identity.loadCurrent" })
|
|
6550
|
+
};
|
|
6551
|
+
return toCapxulResult(loadIdentityProgram, identityDepsLayer(deps));
|
|
6552
|
+
},
|
|
6553
|
+
async usernameAvailable(username, options) {
|
|
6554
|
+
if (options?.signal?.aborted) return {
|
|
6555
|
+
ok: false,
|
|
6556
|
+
error: Errors.cancelled({ operation: "identity.usernameAvailable" })
|
|
6557
|
+
};
|
|
6558
|
+
if (convexCall === void 0) return {
|
|
6559
|
+
ok: false,
|
|
6560
|
+
error: Errors.notImplemented("identity", "usernameAvailable")
|
|
6561
|
+
};
|
|
6562
|
+
return runPortEffect(convexCall.query(usernameAvailableQuery, { username }));
|
|
6563
|
+
}
|
|
6564
|
+
};
|
|
6466
6565
|
}
|
|
6467
6566
|
//#endregion
|
|
6468
6567
|
//#region src/client/_shared/money-telemetry.ts
|
|
@@ -6794,32 +6893,36 @@ function makeFinancialOpsMethods(deps) {
|
|
|
6794
6893
|
} },
|
|
6795
6894
|
destinations: {
|
|
6796
6895
|
add: async (input, options) => {
|
|
6797
|
-
const
|
|
6798
|
-
if (!
|
|
6896
|
+
const scope = normalizeDestinationInputScope(input, "target");
|
|
6897
|
+
if (!scope.ok) return {
|
|
6799
6898
|
ok: false,
|
|
6800
|
-
error:
|
|
6899
|
+
error: scope.error
|
|
6801
6900
|
};
|
|
6802
|
-
|
|
6901
|
+
const scopeValue = scope.value;
|
|
6902
|
+
if (scopeValue === void 0) return {
|
|
6803
6903
|
ok: false,
|
|
6804
|
-
error: Errors.invalidInput("target",
|
|
6904
|
+
error: Errors.invalidInput("target", DESTINATION_SCOPE_MESSAGE)
|
|
6805
6905
|
};
|
|
6906
|
+
const backendActor = actorReferenceToBackend(input.actor);
|
|
6806
6907
|
return mapOk$1(await runIfActive(options?.signal, "destinations.add", () => deps.convexCall.mutation(fns.addDestination, {
|
|
6807
|
-
...
|
|
6808
|
-
ref:
|
|
6908
|
+
...backendActor === void 0 ? {} : { actor: backendActor },
|
|
6909
|
+
...isSelfTarget(scopeValue) ? { self: true } : { ref: scopeValue },
|
|
6809
6910
|
kind: destinationKindToBackend(input.kind),
|
|
6810
6911
|
...input.label === void 0 ? {} : { label: input.label },
|
|
6811
6912
|
payload: input.payload
|
|
6812
6913
|
})), destinationFromBackend);
|
|
6813
6914
|
},
|
|
6814
6915
|
list: async (input, options) => {
|
|
6815
|
-
const
|
|
6816
|
-
if (!
|
|
6916
|
+
const scope = normalizeDestinationInputScope(input, "target");
|
|
6917
|
+
if (!scope.ok) return {
|
|
6817
6918
|
ok: false,
|
|
6818
|
-
error:
|
|
6919
|
+
error: scope.error
|
|
6819
6920
|
};
|
|
6921
|
+
const scopeValue = scope.value;
|
|
6820
6922
|
return mapOk$1(await runIfActive(options?.signal, "destinations.list", () => deps.convexCall.query(fns.listDestinations, {
|
|
6821
6923
|
...input.actor === void 0 ? {} : { actor: actorReferenceToBackend(input.actor) },
|
|
6822
|
-
...
|
|
6924
|
+
...scopeValue !== void 0 && isSelfTarget(scopeValue) ? { self: true } : {},
|
|
6925
|
+
...scopeValue !== void 0 && !isSelfTarget(scopeValue) ? { ref: scopeValue } : {}
|
|
6823
6926
|
})), (destinations) => destinations.map(destinationFromBackend).filter((destination) => input.kind === void 0 || destination.kind === input.kind));
|
|
6824
6927
|
},
|
|
6825
6928
|
remove: (input, options) => runIfActive(options?.signal, "destinations.remove", () => deps.convexCall.mutation(fns.removeDestination, {
|
|
@@ -7094,8 +7197,28 @@ function normalizeTargetForBackend(reference, field) {
|
|
|
7094
7197
|
const ref = refFromTargetReference(reference, field);
|
|
7095
7198
|
return ref.ok ? normalizeRefForBackend(ref.value, field) : ref;
|
|
7096
7199
|
}
|
|
7097
|
-
|
|
7098
|
-
|
|
7200
|
+
const DESTINATION_SCOPE_MESSAGE = "provide exactly one of target or ref; use target: { self: true } for your own destination";
|
|
7201
|
+
/** #1063: detect the `{ self: true }` variant of a destination target. */
|
|
7202
|
+
function isSelfTarget(value) {
|
|
7203
|
+
return "self" in value;
|
|
7204
|
+
}
|
|
7205
|
+
/**
|
|
7206
|
+
* #1063: resolve the public `target`/`ref` pair — `SelfTarget` for the actor's
|
|
7207
|
+
* own destination, a `BackendRef` for a counterparty, `undefined` when unscoped.
|
|
7208
|
+
*/
|
|
7209
|
+
function normalizeDestinationInputScope(input, field) {
|
|
7210
|
+
const target = input.target;
|
|
7211
|
+
if (target !== void 0 && isSelfTarget(target)) {
|
|
7212
|
+
if (input.ref !== void 0) return {
|
|
7213
|
+
ok: false,
|
|
7214
|
+
error: Errors.invalidInput(field, DESTINATION_SCOPE_MESSAGE)
|
|
7215
|
+
};
|
|
7216
|
+
return {
|
|
7217
|
+
ok: true,
|
|
7218
|
+
value: target
|
|
7219
|
+
};
|
|
7220
|
+
}
|
|
7221
|
+
if (target !== void 0) return normalizeTargetForBackend(target, field);
|
|
7099
7222
|
if (input.ref !== void 0) return normalizeDestinationRefForBackend(input.ref, "ref");
|
|
7100
7223
|
return {
|
|
7101
7224
|
ok: true,
|
|
@@ -7191,7 +7314,8 @@ function destinationRailFromBackend(destination) {
|
|
|
7191
7314
|
function destinationFromBackend(destination) {
|
|
7192
7315
|
return {
|
|
7193
7316
|
...destination,
|
|
7194
|
-
target: targetReferenceFromBackendRef(destination.ref),
|
|
7317
|
+
target: destination.ref === null ? null : targetReferenceFromBackendRef(destination.ref),
|
|
7318
|
+
ownerScope: destination.ownerScope ?? "counterparty",
|
|
7195
7319
|
kind: destinationKindFromBackend(destination.kind),
|
|
7196
7320
|
rail: destinationRailFromBackend(destination)
|
|
7197
7321
|
};
|
|
@@ -7278,6 +7402,7 @@ function mapOk$1(result, f) {
|
|
|
7278
7402
|
throw cause;
|
|
7279
7403
|
}
|
|
7280
7404
|
}
|
|
7405
|
+
/** Internal signal-aware Effect→CapxulResult bridge, shared with `media.ts`. */
|
|
7281
7406
|
async function runIfActive(signal, operation, effect) {
|
|
7282
7407
|
if (signal?.aborted === true) return {
|
|
7283
7408
|
ok: false,
|
|
@@ -7294,6 +7419,51 @@ async function runIfActive(signal, operation, effect) {
|
|
|
7294
7419
|
};
|
|
7295
7420
|
}
|
|
7296
7421
|
//#endregion
|
|
7422
|
+
//#region src/client/media.ts
|
|
7423
|
+
const generateUploadUrlFn = makeFunctionReference("media:generateUploadUrl");
|
|
7424
|
+
const setProfileImageFn = makeFunctionReference("media:setProfileImage");
|
|
7425
|
+
const setOrgLogoFn = makeFunctionReference("media:setOrgLogo");
|
|
7426
|
+
function makeMediaMethods(deps) {
|
|
7427
|
+
const fetchImpl = deps.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
7428
|
+
return {
|
|
7429
|
+
async uploadImage(blob, options) {
|
|
7430
|
+
const url = await runIfActive(options?.signal, "media.uploadImage", () => deps.convexCall.mutation(generateUploadUrlFn, {}));
|
|
7431
|
+
if (!url.ok) return url;
|
|
7432
|
+
try {
|
|
7433
|
+
const response = await fetchImpl(url.value.uploadUrl, {
|
|
7434
|
+
method: "POST",
|
|
7435
|
+
headers: { "Content-Type": blob.type },
|
|
7436
|
+
body: blob,
|
|
7437
|
+
...options?.signal === void 0 ? {} : { signal: options.signal }
|
|
7438
|
+
});
|
|
7439
|
+
if (!response.ok) return {
|
|
7440
|
+
ok: false,
|
|
7441
|
+
error: Errors.providerError("convex-storage", "uploadImage", `upload failed with status ${response.status}`)
|
|
7442
|
+
};
|
|
7443
|
+
const parsed = await response.json();
|
|
7444
|
+
if (typeof parsed.storageId !== "string" || parsed.storageId.length === 0) return {
|
|
7445
|
+
ok: false,
|
|
7446
|
+
error: Errors.providerError("convex-storage", "uploadImage", "upload response carried no storageId")
|
|
7447
|
+
};
|
|
7448
|
+
return {
|
|
7449
|
+
ok: true,
|
|
7450
|
+
value: { storageId: parsed.storageId }
|
|
7451
|
+
};
|
|
7452
|
+
} catch (cause) {
|
|
7453
|
+
return {
|
|
7454
|
+
ok: false,
|
|
7455
|
+
error: Errors.providerError("convex-storage", "uploadImage", cause)
|
|
7456
|
+
};
|
|
7457
|
+
}
|
|
7458
|
+
},
|
|
7459
|
+
setProfileImage: (input, options) => runIfActive(options?.signal, "media.setProfileImage", () => deps.convexCall.mutation(setProfileImageFn, { storageId: input.storageId })),
|
|
7460
|
+
setOrgLogo: (input, options) => runIfActive(options?.signal, "media.setOrgLogo", () => deps.convexCall.mutation(setOrgLogoFn, {
|
|
7461
|
+
orgId: input.orgId,
|
|
7462
|
+
storageId: input.storageId
|
|
7463
|
+
}))
|
|
7464
|
+
};
|
|
7465
|
+
}
|
|
7466
|
+
//#endregion
|
|
7297
7467
|
//#region src/client/sub-accounts-deps.ts
|
|
7298
7468
|
var SubAccountsDepsTag = class extends Context.Tag("@capxul/sdk/SubAccountsDeps")() {};
|
|
7299
7469
|
function subAccountsDepsLayer(deps) {
|
|
@@ -7586,7 +7756,10 @@ function hermeticOrgView(input) {
|
|
|
7586
7756
|
handle: input.handle,
|
|
7587
7757
|
safeAddress: toAddress(placeholder),
|
|
7588
7758
|
role: "Owner",
|
|
7589
|
-
treasury: zeroTreasury(orgId)
|
|
7759
|
+
treasury: zeroTreasury(orgId),
|
|
7760
|
+
bio: null,
|
|
7761
|
+
size: null,
|
|
7762
|
+
logoUrl: null
|
|
7590
7763
|
};
|
|
7591
7764
|
}
|
|
7592
7765
|
function moneyFromConfig(input) {
|
|
@@ -8010,7 +8183,8 @@ function validateOrganizationLifecycleScope(orgId, lifecycle) {
|
|
|
8010
8183
|
};
|
|
8011
8184
|
}
|
|
8012
8185
|
/** Advance only the steps still required by one durable Organization lane. */
|
|
8013
|
-
async function advanceOrganizationSetup(setup, orgId, initial,
|
|
8186
|
+
async function advanceOrganizationSetup(setup, orgId, initial, context) {
|
|
8187
|
+
const { signal, observationSource } = context ?? {};
|
|
8014
8188
|
const scopedInitial = validateOrganizationLifecycleScope(orgId, initial);
|
|
8015
8189
|
if (!scopedInitial.ok) return scopedInitial;
|
|
8016
8190
|
let lifecycle = scopedInitial.value;
|
|
@@ -8020,19 +8194,15 @@ async function advanceOrganizationSetup(setup, orgId, initial, signal) {
|
|
|
8020
8194
|
value: lifecycle
|
|
8021
8195
|
};
|
|
8022
8196
|
const currentStep = lifecycle.step;
|
|
8023
|
-
if (signal?.aborted) return recordSetupFailure(setup, orgId, Errors.cancelled({ operation: "organization.setup" }), true);
|
|
8024
|
-
const stepInput = {
|
|
8197
|
+
if (signal?.aborted) return recordSetupFailure(setup, orgId, Errors.cancelled({ operation: "organization.setup" }), true, observationSource);
|
|
8198
|
+
const stepInput = copyInvocationObservation(observationSource, {
|
|
8025
8199
|
orgId,
|
|
8026
8200
|
...signal === void 0 ? {} : { signal }
|
|
8027
|
-
};
|
|
8201
|
+
});
|
|
8028
8202
|
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);
|
|
8029
|
-
if (!next.ok)
|
|
8030
|
-
if (next.error.code === "CANCELLED") return recordSetupFailure(setup, orgId, next.error, true);
|
|
8031
|
-
if (next.error.code === "PROVIDER_ERROR") return recordSetupFailure(setup, orgId, next.error, isRetryableProviderFailure(next.error));
|
|
8032
|
-
return next;
|
|
8033
|
-
}
|
|
8203
|
+
if (!next.ok) return recordSetupFailure(setup, orgId, next.error, isRetryableOrganizationSetupFailure(next.error), observationSource);
|
|
8034
8204
|
const scopedNext = validateOrganizationLifecycleScope(orgId, next.value);
|
|
8035
|
-
if (!scopedNext.ok) return scopedNext;
|
|
8205
|
+
if (!scopedNext.ok) return recordSetupFailure(setup, orgId, scopedNext.error, false, observationSource);
|
|
8036
8206
|
lifecycle = scopedNext.value;
|
|
8037
8207
|
if (currentStep === "confirmingBootstrap") return {
|
|
8038
8208
|
ok: true,
|
|
@@ -8043,7 +8213,7 @@ async function advanceOrganizationSetup(setup, orgId, initial, signal) {
|
|
|
8043
8213
|
ok: true,
|
|
8044
8214
|
value: lifecycle
|
|
8045
8215
|
};
|
|
8046
|
-
return
|
|
8216
|
+
return recordSetupFailure(setup, orgId, Errors.wrongState({
|
|
8047
8217
|
method: "organization.setup",
|
|
8048
8218
|
currentState: lifecycle.step,
|
|
8049
8219
|
validStates: [
|
|
@@ -8051,23 +8221,28 @@ async function advanceOrganizationSetup(setup, orgId, initial, signal) {
|
|
|
8051
8221
|
"ready",
|
|
8052
8222
|
"failed"
|
|
8053
8223
|
]
|
|
8054
|
-
}));
|
|
8224
|
+
}), false, observationSource);
|
|
8055
8225
|
}
|
|
8056
|
-
async function recordSetupFailure(setup, orgId, error, retryable) {
|
|
8057
|
-
const recorded = await setup.recordFailure({
|
|
8226
|
+
async function recordSetupFailure(setup, orgId, error, retryable, observationSource) {
|
|
8227
|
+
const recorded = await setup.recordFailure(copyInvocationObservation(observationSource, {
|
|
8058
8228
|
orgId,
|
|
8059
8229
|
error,
|
|
8060
8230
|
retryable
|
|
8061
|
-
});
|
|
8231
|
+
}));
|
|
8062
8232
|
if (!recorded.ok) return recorded;
|
|
8063
8233
|
const scopedRecorded = validateOrganizationLifecycleScope(orgId, recorded.value);
|
|
8064
8234
|
if (!scopedRecorded.ok) return scopedRecorded;
|
|
8065
|
-
return
|
|
8235
|
+
return scopedRecorded;
|
|
8066
8236
|
}
|
|
8067
8237
|
function isRetryableProviderFailure(error) {
|
|
8068
8238
|
const mode = error.details?.failure_mode;
|
|
8069
8239
|
return mode !== "auth-origin-mismatch" && mode !== "app-env-allowlist" && mode !== "no-secure-context";
|
|
8070
8240
|
}
|
|
8241
|
+
function isRetryableOrganizationSetupFailure(error) {
|
|
8242
|
+
if (error.code === "CANCELLED" || error.code === "SIGNER_REJECTED") return true;
|
|
8243
|
+
if (error.code === "PROVIDER_ERROR") return isRetryableProviderFailure(error);
|
|
8244
|
+
return error.code === "NETWORK_ERROR" || error.code === "UNKNOWN";
|
|
8245
|
+
}
|
|
8071
8246
|
//#endregion
|
|
8072
8247
|
//#region src/client/org.ts
|
|
8073
8248
|
/**
|
|
@@ -8140,12 +8315,15 @@ function makeOrgMethods(deps) {
|
|
|
8140
8315
|
ok: false,
|
|
8141
8316
|
error: Errors.notImplemented("organizationSetup", "retrySetup")
|
|
8142
8317
|
};
|
|
8143
|
-
const retried = await setup.retry({
|
|
8318
|
+
const retried = await setup.retry(copyInvocationObservation(options, {
|
|
8144
8319
|
orgId,
|
|
8145
8320
|
...options?.signal === void 0 ? {} : { signal: options.signal }
|
|
8146
|
-
});
|
|
8321
|
+
}));
|
|
8147
8322
|
if (!retried.ok) return retried;
|
|
8148
|
-
return advanceOrganizationSetup(setup, orgId, retried.value,
|
|
8323
|
+
return advanceOrganizationSetup(setup, orgId, retried.value, {
|
|
8324
|
+
signal: options?.signal,
|
|
8325
|
+
observationSource: options
|
|
8326
|
+
});
|
|
8149
8327
|
},
|
|
8150
8328
|
profile: {
|
|
8151
8329
|
get(_options) {
|
|
@@ -8383,7 +8561,8 @@ async function runCompletePersonalOnboarding(ops, input) {
|
|
|
8383
8561
|
email: session.email,
|
|
8384
8562
|
displayName: validated.value.displayName,
|
|
8385
8563
|
country: validated.value.country,
|
|
8386
|
-
...validated.value.withdrawalAddress === void 0 ? {} : { withdrawalAddress: validated.value.withdrawalAddress }
|
|
8564
|
+
...validated.value.withdrawalAddress === void 0 ? {} : { withdrawalAddress: validated.value.withdrawalAddress },
|
|
8565
|
+
...validated.value.username === void 0 ? {} : { username: validated.value.username }
|
|
8387
8566
|
});
|
|
8388
8567
|
if (!written.ok) return fail(written.error);
|
|
8389
8568
|
const provisioned = await ops.triggerProvisioning();
|
|
@@ -8406,17 +8585,27 @@ async function runCompleteOrganizationOnboarding(ops, input, options) {
|
|
|
8406
8585
|
const written = await ops.completeIdentityOnboarding({
|
|
8407
8586
|
authUserId: session.authUserId,
|
|
8408
8587
|
email: session.email,
|
|
8409
|
-
displayName: validated.value.
|
|
8410
|
-
country: validated.value.country
|
|
8588
|
+
displayName: validated.value.profile.displayName,
|
|
8589
|
+
country: validated.value.profile.country,
|
|
8590
|
+
...validated.value.profile.withdrawalAddress === void 0 ? {} : { withdrawalAddress: validated.value.profile.withdrawalAddress },
|
|
8591
|
+
...validated.value.profile.username === void 0 ? {} : { username: validated.value.profile.username }
|
|
8411
8592
|
});
|
|
8412
8593
|
if (!written.ok) return fail(written.error);
|
|
8413
|
-
const
|
|
8414
|
-
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
|
|
8594
|
+
const founderAccount = await ops.ensureFounderAccountReady(input);
|
|
8595
|
+
if (!founderAccount.ok) return fail(founderAccount.error);
|
|
8596
|
+
if (options?.signal?.aborted === true) return fail(Errors.cancelled({ operation: "onboarding.completeOrganization" }));
|
|
8597
|
+
const started = await setup.startOrResume(copyInvocationObservation(input, {
|
|
8598
|
+
name: validated.value.organization.name,
|
|
8599
|
+
handle: validated.value.organization.handle,
|
|
8600
|
+
country: validated.value.organization.country,
|
|
8601
|
+
...validated.value.organization.bio === void 0 ? {} : { bio: validated.value.organization.bio },
|
|
8602
|
+
...validated.value.organization.size === void 0 ? {} : { size: validated.value.organization.size }
|
|
8603
|
+
}));
|
|
8418
8604
|
if (!started.ok) return fail(started.error);
|
|
8419
|
-
const lifecycle = await advanceOrganizationSetup(setup, started.value.orgId, started.value.lifecycle,
|
|
8605
|
+
const lifecycle = await advanceOrganizationSetup(setup, started.value.orgId, started.value.lifecycle, {
|
|
8606
|
+
signal: options?.signal,
|
|
8607
|
+
observationSource: input
|
|
8608
|
+
});
|
|
8420
8609
|
if (!lifecycle.ok) {
|
|
8421
8610
|
const error = lifecycle.error;
|
|
8422
8611
|
return fail(new CapxulError(error.code, error.message, {
|
|
@@ -8438,44 +8627,61 @@ async function runCompleteOrganizationOnboarding(ops, input, options) {
|
|
|
8438
8627
|
};
|
|
8439
8628
|
}
|
|
8440
8629
|
function validatePersonalInput(input) {
|
|
8441
|
-
|
|
8442
|
-
|
|
8443
|
-
|
|
8630
|
+
if (!isRecord(input) || !isRecord(input.profile)) return fail(Errors.invalidInput("profile", "must be an object"));
|
|
8631
|
+
return validateProfileInput(input.profile);
|
|
8632
|
+
}
|
|
8633
|
+
function validateOrganizationInput(input) {
|
|
8634
|
+
if (!isRecord(input) || !isRecord(input.profile)) return fail(Errors.invalidInput("profile", "must be an object"));
|
|
8635
|
+
if (!isRecord(input.organization)) return fail(Errors.invalidInput("organization", "must be an object"));
|
|
8636
|
+
const profile = validateProfileInput(input.profile);
|
|
8637
|
+
if (!profile.ok) return profile;
|
|
8638
|
+
const name = requireNonEmpty(input.organization.name, "organization.name");
|
|
8639
|
+
if (!name.ok) return name;
|
|
8640
|
+
const handle = requireNonEmpty(input.organization.handle, "organization.handle");
|
|
8641
|
+
if (!handle.ok) return handle;
|
|
8642
|
+
const country = parseCountry(input.organization.country, "organization.country");
|
|
8444
8643
|
if (!country.ok) return country;
|
|
8445
|
-
if (input.withdrawalAddress === void 0) return {
|
|
8446
|
-
ok: true,
|
|
8447
|
-
value: {
|
|
8448
|
-
displayName: displayName.value,
|
|
8449
|
-
country: country.value
|
|
8450
|
-
}
|
|
8451
|
-
};
|
|
8452
|
-
const withdrawalAddress = parseAddress(input.withdrawalAddress, "withdrawalAddress");
|
|
8453
|
-
if (!withdrawalAddress.ok) return withdrawalAddress;
|
|
8454
8644
|
return {
|
|
8455
8645
|
ok: true,
|
|
8456
8646
|
value: {
|
|
8457
|
-
|
|
8458
|
-
|
|
8459
|
-
|
|
8647
|
+
profile: profile.value,
|
|
8648
|
+
organization: {
|
|
8649
|
+
name: name.value,
|
|
8650
|
+
handle: handle.value,
|
|
8651
|
+
country: country.value,
|
|
8652
|
+
...input.organization.bio === void 0 ? {} : { bio: input.organization.bio },
|
|
8653
|
+
...input.organization.size === void 0 ? {} : { size: input.organization.size }
|
|
8654
|
+
}
|
|
8460
8655
|
}
|
|
8461
8656
|
};
|
|
8462
8657
|
}
|
|
8463
|
-
function
|
|
8464
|
-
const
|
|
8465
|
-
if (!
|
|
8466
|
-
const
|
|
8467
|
-
if (!handle.ok) return handle;
|
|
8468
|
-
const ownerDisplayName = requireNonEmpty(input.ownerDisplayName, "ownerDisplayName");
|
|
8469
|
-
if (!ownerDisplayName.ok) return ownerDisplayName;
|
|
8470
|
-
const country = parseCountry(input.country);
|
|
8658
|
+
function validateProfileInput(input) {
|
|
8659
|
+
const displayName = requireNonEmpty(input.displayName, "profile.displayName");
|
|
8660
|
+
if (!displayName.ok) return displayName;
|
|
8661
|
+
const country = parseCountry(input.country, "profile.country");
|
|
8471
8662
|
if (!country.ok) return country;
|
|
8663
|
+
let username;
|
|
8664
|
+
if (input.username !== void 0) {
|
|
8665
|
+
const parsed = requireNonEmpty(input.username, "profile.username");
|
|
8666
|
+
if (!parsed.ok) return parsed;
|
|
8667
|
+
username = parsed.value;
|
|
8668
|
+
}
|
|
8669
|
+
const base = {
|
|
8670
|
+
displayName: displayName.value,
|
|
8671
|
+
country: country.value,
|
|
8672
|
+
...username === void 0 ? {} : { username }
|
|
8673
|
+
};
|
|
8674
|
+
if (input.withdrawalAddress === void 0) return {
|
|
8675
|
+
ok: true,
|
|
8676
|
+
value: base
|
|
8677
|
+
};
|
|
8678
|
+
const withdrawalAddress = parseAddress(input.withdrawalAddress, "profile.withdrawalAddress");
|
|
8679
|
+
if (!withdrawalAddress.ok) return withdrawalAddress;
|
|
8472
8680
|
return {
|
|
8473
8681
|
ok: true,
|
|
8474
8682
|
value: {
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
country: country.value,
|
|
8478
|
-
ownerDisplayName: ownerDisplayName.value
|
|
8683
|
+
...base,
|
|
8684
|
+
withdrawalAddress: withdrawalAddress.value
|
|
8479
8685
|
}
|
|
8480
8686
|
};
|
|
8481
8687
|
}
|
|
@@ -8487,14 +8693,14 @@ function requireNonEmpty(value, field) {
|
|
|
8487
8693
|
value: trimmed
|
|
8488
8694
|
};
|
|
8489
8695
|
}
|
|
8490
|
-
function parseCountry(value) {
|
|
8696
|
+
function parseCountry(value, field = "country") {
|
|
8491
8697
|
try {
|
|
8492
8698
|
return {
|
|
8493
8699
|
ok: true,
|
|
8494
8700
|
value: toCountryCode(value)
|
|
8495
8701
|
};
|
|
8496
8702
|
} catch (cause) {
|
|
8497
|
-
return fail(invalidFrom(
|
|
8703
|
+
return fail(invalidFrom(field, cause, "must be an ISO-3166 alpha-2 code"));
|
|
8498
8704
|
}
|
|
8499
8705
|
}
|
|
8500
8706
|
function parseAddress(value, field) {
|
|
@@ -8511,6 +8717,9 @@ function invalidFrom(field, cause, fallback) {
|
|
|
8511
8717
|
const message = cause instanceof Error && cause.message.length > 0 ? cause.message : fallback;
|
|
8512
8718
|
return Errors.invalidInput(field, message);
|
|
8513
8719
|
}
|
|
8720
|
+
function isRecord(value) {
|
|
8721
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8722
|
+
}
|
|
8514
8723
|
function fail(error) {
|
|
8515
8724
|
return {
|
|
8516
8725
|
ok: false,
|
|
@@ -8602,8 +8811,10 @@ function assembleCapxulClient(input) {
|
|
|
8602
8811
|
});
|
|
8603
8812
|
const identity = makeIdentityMethods({
|
|
8604
8813
|
identityPort: input.ports.identity,
|
|
8605
|
-
actor
|
|
8814
|
+
actor,
|
|
8815
|
+
convexCall: input.ports.convexCall
|
|
8606
8816
|
});
|
|
8817
|
+
const media = makeMediaMethods({ convexCall: input.ports.convexCall });
|
|
8607
8818
|
const accounts = makeAccountsMethods({
|
|
8608
8819
|
accountReadPort: input.ports.accountRead,
|
|
8609
8820
|
chainId: input.bootstrap.chainId,
|
|
@@ -8640,6 +8851,22 @@ function assembleCapxulClient(input) {
|
|
|
8640
8851
|
};
|
|
8641
8852
|
},
|
|
8642
8853
|
completeIdentityOnboarding: (write) => runPortEffect(input.ports.identity.completeOnboarding(write)),
|
|
8854
|
+
ensureFounderAccountReady: async (observationSource) => {
|
|
8855
|
+
const deployed = await account._internal.deploySafe(observationSource);
|
|
8856
|
+
if (!deployed.ok) return deployed;
|
|
8857
|
+
if (deployed.value.deployedAt === null || deployed.value.claimedAt === null) return {
|
|
8858
|
+
ok: false,
|
|
8859
|
+
error: Errors.wrongState({
|
|
8860
|
+
method: "onboarding.completeOrganization",
|
|
8861
|
+
currentState: "founderAccountClaimPending",
|
|
8862
|
+
validStates: ["founderAccountDeployedAndClaimed"]
|
|
8863
|
+
})
|
|
8864
|
+
};
|
|
8865
|
+
return {
|
|
8866
|
+
ok: true,
|
|
8867
|
+
value: void 0
|
|
8868
|
+
};
|
|
8869
|
+
},
|
|
8643
8870
|
triggerProvisioning: () => account._internal.provision(),
|
|
8644
8871
|
kickProvisioning: () => kickProvisioning?.(),
|
|
8645
8872
|
readLifecycle: () => account.getLifecycle(),
|
|
@@ -8663,6 +8890,7 @@ function assembleCapxulClient(input) {
|
|
|
8663
8890
|
paymentDocuments: financialOps.paymentDocuments,
|
|
8664
8891
|
paymentRequests: financialOps.paymentRequests,
|
|
8665
8892
|
workbench: financialOps.workbench,
|
|
8893
|
+
media,
|
|
8666
8894
|
subAccounts,
|
|
8667
8895
|
createOrg: orgMethods.createOrg,
|
|
8668
8896
|
orgs: orgMethods.orgs,
|
|
@@ -8802,7 +9030,7 @@ function observeSdkClient(client, adapter) {
|
|
|
8802
9030
|
if (cached !== void 0) return cached;
|
|
8803
9031
|
const wrapped = new Proxy(callable, {
|
|
8804
9032
|
apply(currentTarget, _thisArg, args) {
|
|
8805
|
-
const invocationContext = resolveAdapterContext(adapter);
|
|
9033
|
+
const invocationContext = invocationObservationContext(resolveAdapterContext(adapter));
|
|
8806
9034
|
const invocationArgs = carryInvocationContext(operation, args, invocationContext);
|
|
8807
9035
|
let output;
|
|
8808
9036
|
try {
|
|
@@ -8839,9 +9067,23 @@ function observeSdkClient(client, adapter) {
|
|
|
8839
9067
|
return wrapObject(client, []);
|
|
8840
9068
|
}
|
|
8841
9069
|
function carryInvocationContext(operation, args, context) {
|
|
8842
|
-
if (
|
|
9070
|
+
if (!isPlainObject(args[0])) return args.length === 0 && operation === "org.retrySetup" ? [attachInvocationObservation({}, context)] : args;
|
|
8843
9071
|
return [attachInvocationObservation({ ...args[0] }, context), ...args.slice(1)];
|
|
8844
9072
|
}
|
|
9073
|
+
/** One stable correlation id per public call; the next call is an explicit retry. */
|
|
9074
|
+
function invocationObservationContext(context) {
|
|
9075
|
+
return {
|
|
9076
|
+
...context,
|
|
9077
|
+
correlationId: createInvocationCorrelationId()
|
|
9078
|
+
};
|
|
9079
|
+
}
|
|
9080
|
+
function createInvocationCorrelationId() {
|
|
9081
|
+
if (typeof globalThis.crypto?.randomUUID === "function") return `sdk_${globalThis.crypto.randomUUID()}`;
|
|
9082
|
+
const bytes = new Uint8Array(16);
|
|
9083
|
+
if (typeof globalThis.crypto?.getRandomValues === "function") globalThis.crypto.getRandomValues(bytes);
|
|
9084
|
+
else for (let index = 0; index < bytes.length; index += 1) bytes[index] = Math.floor(Math.random() * 256);
|
|
9085
|
+
return `sdk_${Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
9086
|
+
}
|
|
8845
9087
|
/** @internal Reports a factory-level typed failure without changing its identity. */
|
|
8846
9088
|
function observeFailedResult(result, adapter, operation) {
|
|
8847
9089
|
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterContext(adapter));
|
|
@@ -8890,6 +9132,7 @@ function observationContextProps(context) {
|
|
|
8890
9132
|
if (context?.release !== void 0) props.release = context.release;
|
|
8891
9133
|
if (context?.sessionId !== void 0) props.session_id = context.sessionId;
|
|
8892
9134
|
if (context?.organizationId !== void 0) props.organization_id = context.organizationId;
|
|
9135
|
+
if (context?.journeyId !== void 0) props.journey_id = context.journeyId;
|
|
8893
9136
|
if (context?.correlationId !== void 0) props.correlation_id = context.correlationId;
|
|
8894
9137
|
if (context?.anonymousId !== void 0) props.anonymous_id = context.anonymousId;
|
|
8895
9138
|
return props;
|
|
@@ -9315,7 +9558,8 @@ async function createCapxulClient$1(input) {
|
|
|
9315
9558
|
orgPort: new ConvexOrganizationAdapter({ convex: adapters.value.ports.convexCall }),
|
|
9316
9559
|
...signer === void 0 ? {} : { organizationSetup: new ConvexOrganizationSetupAdapter({
|
|
9317
9560
|
convex: adapters.value.ports.convexCall,
|
|
9318
|
-
signer
|
|
9561
|
+
signer,
|
|
9562
|
+
chainId: adapters.value.bootstrap.chainId
|
|
9319
9563
|
}) },
|
|
9320
9564
|
...input.signal === void 0 ? {} : { signal: input.signal },
|
|
9321
9565
|
...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs },
|
|
@@ -9586,6 +9830,6 @@ function telemetryFromPostHog(client, options = {}) {
|
|
|
9586
9830
|
});
|
|
9587
9831
|
}
|
|
9588
9832
|
//#endregion
|
|
9589
|
-
export { CAPXUL_SDK_EXPECTED_OUTCOME_EVENT, CapxulError, captureException, captureExceptionSync, createCapxulClient, deriveDevPrivateKey, devPrivateKeySigner, eip1193AccountProvider, embeddedSigner, fromPostHog, injectedWalletSigner, isCapxulError, isSettingUpLifecycle, localPrivateKeyAccountProvider, openfortEmbeddedSigner, openfortEmbeddedSignerFromWallet, openfortEmbeddedWalletPort, telemetryFromPostHog };
|
|
9833
|
+
export { CAPXUL_SDK_EXPECTED_OUTCOME_EVENT, CapxulError, captureException, captureExceptionSync, createCapxulClient, deriveDevPrivateKey, devPrivateKeySigner, eip1193AccountProvider, embeddedSigner, fromPostHog, injectedWalletSigner, isCapxulError, isSettingUpLifecycle, localPrivateKeyAccountProvider, openfortEmbeddedSigner, openfortEmbeddedSignerFromWallet, openfortEmbeddedWalletPort, telemetryFromPostHog, toCountryCode, toAddress as toEvmAddress };
|
|
9590
9834
|
|
|
9591
9835
|
//# sourceMappingURL=index.mjs.map
|