@capxul/mcp 1.0.0-alpha.16 → 1.0.0-alpha.18
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 +31 -62
- package/dist/{alchemy-rpc-mjuofdCf.mjs → alchemy-rpc-C6k1xrCi.mjs} +2 -2
- package/dist/alchemy-rpc-DRpULec2.mjs +2 -0
- package/dist/main.mjs +1015 -411
- package/dist/src-CIqRZpwl.mjs +2 -0
- package/dist/{src-BDIKpZXn.mjs → src-DM3bg5NZ.mjs} +912 -785
- package/package.json +5 -5
- package/dist/alchemy-rpc-DxVP2GsG.mjs +0 -2
- package/dist/src-BmSYoMhj.mjs +0 -2
package/dist/main.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { $ as
|
|
3
|
-
import { a as fetchEntryPointNonce, c as fetchUserOperationReceipt, d as sendUserOperation, i as fetchCommitmentState, l as getPaymasterData, n as estimateUserOperationGas, o as fetchErc20Balance, s as fetchUserOperationFees, u as getPaymasterStubData } from "./alchemy-rpc-
|
|
2
|
+
import { $ as buildCapxulCommitmentRedirectCallData, A as SAFE_MODULE_SETUP, C as BASE_SEPOLIA_CHAIN_ID, D as MULTI_SEND, F as deriveCapxulSafeAddress, H as safe4337StubSignature, K as ERC20_APPROVE_ABI, M as SAFE_PROXY_FACTORY, N as buildSafeMultiSendExecTransactionCall, O as SAFE_4337_MODULE, P as computeCapxulSafeSaltNonce, Q as buildCapxulCommitmentClaimCallData, R as packSafe4337OwnerSignature, S as normalizeBindingEmail, U as CAPXUL_PAYMENTS_ADDRESS, V as safe4337SafeOpDigest, Z as buildCapxulCommitmentCancelCallData, a as computeOrgRolesModuleAddress, at as buildOrgRoleSpendPersonalCallData, ct as isExactTransferTokenAllowed, dt as Errors, et as buildCapxulCreateCommitmentPersonalCallData, g as deriveCapxulOrgAddress, h as computeCapxulOrgSaltNonce, i as buildOrgRolesDeployCalls, it as buildOrgPersonalMultiCallData, k as SAFE_L2_SINGLETON, l as orgRoleKeyForLabel, lt as decodeConvexError, m as buildCapxulOrgInitializer, nt as buildCapxulPaymentsRoleBatchSpendCall, pt as isCapxulError, r as buildOrgRoleAssignmentCall, s as compileOrgRoleDefinitions, st as USDX_ADDRESS_BASE_SEPOLIA, tt as buildCapxulPaymentsPersonalSendCallData, u as orgRoleTemplateDefinitions, ut as CapxulError, y as DIRECT_BASE_ROUTE } from "./src-DM3bg5NZ.mjs";
|
|
3
|
+
import { a as fetchEntryPointNonce, c as fetchUserOperationReceipt, d as sendUserOperation, i as fetchCommitmentState, l as getPaymasterData, n as estimateUserOperationGas, o as fetchErc20Balance, s as fetchUserOperationFees, u as getPaymasterStubData } from "./alchemy-rpc-C6k1xrCi.mjs";
|
|
4
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
5
|
import { createHash, randomBytes } from "node:crypto";
|
|
6
6
|
import { createServer } from "node:http";
|
|
7
7
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
8
8
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
9
|
-
import { concat, concatHex, createPublicClient, createWalletClient, custom, decodeAbiParameters, decodeFunctionData, encodeAbiParameters, encodeFunctionData, encodePacked, formatUnits, getAddress, getContractAddress, hashMessage, hashTypedData, hexToBigInt, http, keccak256, pad,
|
|
9
|
+
import { concat, concatHex, createPublicClient, createWalletClient, custom, decodeAbiParameters, decodeFunctionData, encodeAbiParameters, encodeFunctionData, encodePacked, formatUnits, getAddress, getContractAddress, hashMessage, hashTypedData, hexToBigInt, http, keccak256, pad, parseUnits, recoverAddress, size, slice, stringToHex, toBytes, toHex, zeroAddress } from "viem";
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
import { Schema, TreeFormatter } from "@effect/schema";
|
|
12
12
|
import { Context, Data, Deferred, Duration, Effect, Either, Exit, Layer, Ref, Request, Scope } from "effect";
|
|
@@ -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.18";
|
|
236
236
|
//#endregion
|
|
237
237
|
//#region src/tool-result.ts
|
|
238
238
|
function okResult(structured) {
|
|
@@ -1152,7 +1152,7 @@ const PaymentSource = Schema.Union(Schema.Struct({
|
|
|
1152
1152
|
* `hashLineItems` (payment-document-hash.ts) into the Invoice `lineItemsHash`,
|
|
1153
1153
|
* and Σ(quantity × unitMinor) MUST equal the invoice `amount`. The hash binds
|
|
1154
1154
|
* the documentHash to the exact items; the sum-check makes the items add up to
|
|
1155
|
-
* the amount due. See the
|
|
1155
|
+
* the amount due. See the financial-operations contract in `packages/wire/CONTEXT.md`.
|
|
1156
1156
|
*/
|
|
1157
1157
|
const LineItem = Schema.Struct({
|
|
1158
1158
|
description: Schema.String,
|
|
@@ -1609,6 +1609,82 @@ function redactError(error, operation, replace) {
|
|
|
1609
1609
|
};
|
|
1610
1610
|
}
|
|
1611
1611
|
//#endregion
|
|
1612
|
+
//#region ../../packages/wire/src/secret-material.ts
|
|
1613
|
+
const SENSITIVE_MATERIAL_PATTERNS = [
|
|
1614
|
+
/0x[a-fA-F0-9]{40,}/u,
|
|
1615
|
+
/(?:^|[^a-fA-F0-9])[a-fA-F0-9]{64}(?:$|[^a-fA-F0-9])/u,
|
|
1616
|
+
/eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/u,
|
|
1617
|
+
/(?:(?:sk|pk|rk)_(?:live|test)|(?:phc|phx|ghp|gho|ghu|ghs|ghr|whsec)_|github_pat_|xox[baprs]-|AKIA[0-9A-Z]{16}|AIza)[A-Za-z0-9_-]*/iu
|
|
1618
|
+
];
|
|
1619
|
+
/**
|
|
1620
|
+
* Reject: does the value carry any known secret material? Best effort — callers
|
|
1621
|
+
* drop the whole value on a match; a false negative is a leak, a false positive
|
|
1622
|
+
* merely omits an observation field.
|
|
1623
|
+
*/
|
|
1624
|
+
function containsSensitiveMaterial(value) {
|
|
1625
|
+
return SENSITIVE_MATERIAL_PATTERNS.some((pattern) => pattern.test(value));
|
|
1626
|
+
}
|
|
1627
|
+
//#endregion
|
|
1628
|
+
//#region ../../packages/wire/src/observation-context.ts
|
|
1629
|
+
/** Single bounded HTTP carrier used before a Convex action envelope exists. */
|
|
1630
|
+
const OBSERVATION_CONTEXT_HEADER = "x-capxul-observation-context";
|
|
1631
|
+
const FIELD_RULES = {
|
|
1632
|
+
application: {
|
|
1633
|
+
maxLength: 64,
|
|
1634
|
+
pattern: /^[A-Za-z0-9][A-Za-z0-9._-]*$/u
|
|
1635
|
+
},
|
|
1636
|
+
applicationId: {
|
|
1637
|
+
maxLength: 30,
|
|
1638
|
+
pattern: APP_ID_RE
|
|
1639
|
+
},
|
|
1640
|
+
release: {
|
|
1641
|
+
maxLength: 128,
|
|
1642
|
+
pattern: /^[A-Za-z0-9][A-Za-z0-9._+@:/-]*$/u
|
|
1643
|
+
},
|
|
1644
|
+
sessionId: {
|
|
1645
|
+
maxLength: 128,
|
|
1646
|
+
pattern: /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u
|
|
1647
|
+
},
|
|
1648
|
+
organizationId: {
|
|
1649
|
+
maxLength: 128,
|
|
1650
|
+
pattern: /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u
|
|
1651
|
+
},
|
|
1652
|
+
correlationId: {
|
|
1653
|
+
maxLength: 128,
|
|
1654
|
+
pattern: /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u
|
|
1655
|
+
},
|
|
1656
|
+
anonymousId: {
|
|
1657
|
+
maxLength: 128,
|
|
1658
|
+
pattern: /^anon_[A-Za-z0-9-]+$/u
|
|
1659
|
+
}
|
|
1660
|
+
};
|
|
1661
|
+
/**
|
|
1662
|
+
* Copy only the canonical allowlist and silently omit malformed/sensitive
|
|
1663
|
+
* values. Observation metadata is best effort and may never reject a domain
|
|
1664
|
+
* operation.
|
|
1665
|
+
*/
|
|
1666
|
+
function sanitizeObservationContext(input) {
|
|
1667
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) return void 0;
|
|
1668
|
+
const source = input;
|
|
1669
|
+
const sanitized = {};
|
|
1670
|
+
for (const field of Object.keys(FIELD_RULES)) {
|
|
1671
|
+
const value = source[field];
|
|
1672
|
+
if (!isSafeField(field, value)) continue;
|
|
1673
|
+
sanitized[field] = value;
|
|
1674
|
+
}
|
|
1675
|
+
return Object.keys(sanitized).length === 0 ? void 0 : sanitized;
|
|
1676
|
+
}
|
|
1677
|
+
/** Encode only the sanitized allowlist; absence stays absence. */
|
|
1678
|
+
function encodeObservationContextHeader(input) {
|
|
1679
|
+
const sanitized = sanitizeObservationContext(input);
|
|
1680
|
+
return sanitized === void 0 ? void 0 : JSON.stringify(sanitized);
|
|
1681
|
+
}
|
|
1682
|
+
function isSafeField(field, value) {
|
|
1683
|
+
if (typeof value !== "string") return false;
|
|
1684
|
+
const rule = FIELD_RULES[field];
|
|
1685
|
+
return value.length > 0 && value.length <= rule.maxLength && value === value.trim() && !value.includes("://") && !containsSensitiveMaterial(value) && rule.pattern.test(value);
|
|
1686
|
+
}
|
|
1687
|
+
//#endregion
|
|
1612
1688
|
//#region src/payment-wire.ts
|
|
1613
1689
|
const MONEY_RE$1 = /^\s*([0-9]+(?:\.[0-9]+)?)\s+([A-Za-z][A-Za-z0-9]*)\s*$/;
|
|
1614
1690
|
const MONEY_SCHEMA = z.object({
|
|
@@ -5192,7 +5268,7 @@ async function recoverRawDigestSigner(input) {
|
|
|
5192
5268
|
}
|
|
5193
5269
|
//#endregion
|
|
5194
5270
|
//#region ../../packages/sdk/package.json
|
|
5195
|
-
var version = "1.0.0-alpha.
|
|
5271
|
+
var version = "1.0.0-alpha.18";
|
|
5196
5272
|
//#endregion
|
|
5197
5273
|
//#region ../../packages/sdk/src/ports/auth-client.ts
|
|
5198
5274
|
var AuthClientError = class extends Data.TaggedError("AuthClientError") {};
|
|
@@ -5238,6 +5314,18 @@ function resolveAuthClientUrl(authBaseUrl, path) {
|
|
|
5238
5314
|
return `${base}${path}`;
|
|
5239
5315
|
}
|
|
5240
5316
|
//#endregion
|
|
5317
|
+
//#region ../../packages/sdk/src/internal/observation-http.ts
|
|
5318
|
+
/** Resolve one bounded pre-auth snapshot for an outbound SDK HTTP request. */
|
|
5319
|
+
function observationRequestHeaders(adapter) {
|
|
5320
|
+
if (adapter === void 0) return {};
|
|
5321
|
+
try {
|
|
5322
|
+
const encoded = encodeObservationContextHeader(adapter.resolveContext?.());
|
|
5323
|
+
return encoded === void 0 ? {} : { [OBSERVATION_CONTEXT_HEADER]: encoded };
|
|
5324
|
+
} catch {
|
|
5325
|
+
return {};
|
|
5326
|
+
}
|
|
5327
|
+
}
|
|
5328
|
+
//#endregion
|
|
5241
5329
|
//#region ../../packages/sdk/src/adapters/auth-client/BetterAuthBrowserAdapter.ts
|
|
5242
5330
|
function withSignal$1(init, signal) {
|
|
5243
5331
|
return signal === void 0 ? init : {
|
|
@@ -5295,8 +5383,10 @@ function mapFetchError$1(operation, err, signal) {
|
|
|
5295
5383
|
var BetterAuthBrowserAdapter = class {
|
|
5296
5384
|
authBaseUrl;
|
|
5297
5385
|
fetchImpl;
|
|
5386
|
+
observation;
|
|
5298
5387
|
constructor(deps) {
|
|
5299
5388
|
this.authBaseUrl = deps.authBaseUrl.replace(/\/$/, "");
|
|
5389
|
+
this.observation = deps.observation;
|
|
5300
5390
|
this.fetchImpl = deps.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
5301
5391
|
}
|
|
5302
5392
|
url(path) {
|
|
@@ -5323,7 +5413,10 @@ var BetterAuthBrowserAdapter = class {
|
|
|
5323
5413
|
try {
|
|
5324
5414
|
const res = await this.fetchImpl(this.url("/api/auth/email-otp/send-verification-otp"), withSignal$1({
|
|
5325
5415
|
method: "POST",
|
|
5326
|
-
headers: {
|
|
5416
|
+
headers: {
|
|
5417
|
+
"Content-Type": "application/json",
|
|
5418
|
+
...observationRequestHeaders(this.observation)
|
|
5419
|
+
},
|
|
5327
5420
|
body: JSON.stringify({
|
|
5328
5421
|
email: input.email,
|
|
5329
5422
|
type: "sign-in"
|
|
@@ -5697,12 +5790,14 @@ var BetterAuthNodeAdapter = class {
|
|
|
5697
5790
|
origin;
|
|
5698
5791
|
cookieJar;
|
|
5699
5792
|
fetchImpl;
|
|
5793
|
+
observation;
|
|
5700
5794
|
constructor(deps) {
|
|
5701
5795
|
this.authBaseUrl = deps.authBaseUrl.replace(/\/$/, "");
|
|
5702
5796
|
this.host = hostFromBaseUrl(this.authBaseUrl);
|
|
5703
5797
|
this.origin = deps.origin?.replace(/\/$/, "");
|
|
5704
5798
|
this.cookieJar = deps.cookieJar ?? new CookieJar();
|
|
5705
5799
|
this.fetchImpl = deps.fetch ?? fetch;
|
|
5800
|
+
this.observation = deps.observation;
|
|
5706
5801
|
}
|
|
5707
5802
|
url(path) {
|
|
5708
5803
|
return resolveAuthClientUrl(this.authBaseUrl, path);
|
|
@@ -5737,7 +5832,8 @@ var BetterAuthNodeAdapter = class {
|
|
|
5737
5832
|
method: "POST",
|
|
5738
5833
|
headers: {
|
|
5739
5834
|
"content-type": "application/json",
|
|
5740
|
-
...this.origin ? { origin: this.origin } : {}
|
|
5835
|
+
...this.origin ? { origin: this.origin } : {},
|
|
5836
|
+
...observationRequestHeaders(this.observation)
|
|
5741
5837
|
},
|
|
5742
5838
|
body: JSON.stringify({
|
|
5743
5839
|
email: input.email,
|
|
@@ -5978,8 +6074,10 @@ async function safeText(res) {
|
|
|
5978
6074
|
var HttpBootstrapAdapter = class {
|
|
5979
6075
|
bootstrapBaseUrl;
|
|
5980
6076
|
fetchImpl;
|
|
6077
|
+
observation;
|
|
5981
6078
|
constructor(deps) {
|
|
5982
6079
|
this.bootstrapBaseUrl = deps.bootstrapBaseUrl.replace(/\/$/, "");
|
|
6080
|
+
this.observation = deps.observation;
|
|
5983
6081
|
this.fetchImpl = deps.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
5984
6082
|
}
|
|
5985
6083
|
resolve(input) {
|
|
@@ -5987,7 +6085,8 @@ var HttpBootstrapAdapter = class {
|
|
|
5987
6085
|
try: () => {
|
|
5988
6086
|
const headers = {
|
|
5989
6087
|
"content-type": "application/json",
|
|
5990
|
-
...input.origin === void 0 ? {} : { origin: input.origin }
|
|
6088
|
+
...input.origin === void 0 ? {} : { origin: input.origin },
|
|
6089
|
+
...observationRequestHeaders(this.observation)
|
|
5991
6090
|
};
|
|
5992
6091
|
return this.fetchImpl(`${this.bootstrapBaseUrl}/v1/client/bootstrap`, {
|
|
5993
6092
|
method: "POST",
|
|
@@ -6081,13 +6180,54 @@ function convexCallErrorFromCapxul(operation, error) {
|
|
|
6081
6180
|
}
|
|
6082
6181
|
var ConvexCallPortTag = class extends Context.Tag("@capxul/sdk/ports/ConvexCallPort")() {};
|
|
6083
6182
|
//#endregion
|
|
6183
|
+
//#region ../../packages/sdk/src/internal/invocation-observation.ts
|
|
6184
|
+
const INVOCATION_OBSERVATION = Symbol("capxul.invocation-observation");
|
|
6185
|
+
const FAILURE_INVOCATION_SNAPSHOT = Symbol("capxul.failure-invocation-snapshot");
|
|
6186
|
+
/** @internal Attach one immutable, non-wire invocation snapshot to an SDK-owned object. */
|
|
6187
|
+
function attachInvocationObservation(target, context) {
|
|
6188
|
+
const snapshot = Object.freeze(context === void 0 ? {} : { context: Object.freeze({ ...context }) });
|
|
6189
|
+
Object.defineProperty(target, INVOCATION_OBSERVATION, {
|
|
6190
|
+
configurable: false,
|
|
6191
|
+
enumerable: false,
|
|
6192
|
+
value: snapshot,
|
|
6193
|
+
writable: false
|
|
6194
|
+
});
|
|
6195
|
+
return target;
|
|
6196
|
+
}
|
|
6197
|
+
/** @internal Read the snapshot without exposing its symbol or adding a wire field. */
|
|
6198
|
+
function readInvocationObservation(source) {
|
|
6199
|
+
if (typeof source !== "object" || source === null) return void 0;
|
|
6200
|
+
return source[INVOCATION_OBSERVATION];
|
|
6201
|
+
}
|
|
6202
|
+
/** @internal Carry a snapshot across an SDK adapter projection without resolving again. */
|
|
6203
|
+
function copyInvocationObservation(source, target) {
|
|
6204
|
+
const snapshot = readInvocationObservation(source);
|
|
6205
|
+
return snapshot === void 0 ? target : attachInvocationObservation(target, snapshot.context);
|
|
6206
|
+
}
|
|
6207
|
+
/** @internal Mark a failure envelope as already resolved at the public invocation boundary. */
|
|
6208
|
+
function markFailureInvocationSnapshot(failure) {
|
|
6209
|
+
Object.defineProperty(failure, FAILURE_INVOCATION_SNAPSHOT, {
|
|
6210
|
+
configurable: false,
|
|
6211
|
+
enumerable: false,
|
|
6212
|
+
value: true,
|
|
6213
|
+
writable: false
|
|
6214
|
+
});
|
|
6215
|
+
return failure;
|
|
6216
|
+
}
|
|
6217
|
+
//#endregion
|
|
6084
6218
|
//#region ../../packages/sdk/src/adapters/convex-call/ConvexCallAdapter.ts
|
|
6219
|
+
/** Exact floor-first allowlist; every additional handler must migrate its validator first. */
|
|
6220
|
+
const OBSERVED_CONVEX_ACTIONS = new Set(["subAccount/actions:transfer"]);
|
|
6085
6221
|
var ConvexCallAdapter = class {
|
|
6086
6222
|
#client;
|
|
6087
6223
|
#tokenProvider;
|
|
6224
|
+
#applicationId;
|
|
6225
|
+
#observation;
|
|
6088
6226
|
constructor(deps) {
|
|
6089
6227
|
this.#client = deps.client ?? new ConvexClient(deps.convexUrl);
|
|
6090
6228
|
this.#tokenProvider = deps.tokenProvider;
|
|
6229
|
+
this.#applicationId = deps.applicationId;
|
|
6230
|
+
this.#observation = deps.observation;
|
|
6091
6231
|
if (this.#tokenProvider) this.#client.setAuth(this.#tokenProvider);
|
|
6092
6232
|
}
|
|
6093
6233
|
refreshAuth() {
|
|
@@ -6106,10 +6246,36 @@ var ConvexCallAdapter = class {
|
|
|
6106
6246
|
});
|
|
6107
6247
|
}
|
|
6108
6248
|
action(fn, args) {
|
|
6249
|
+
const path = getFunctionName(fn);
|
|
6109
6250
|
return Effect.tryPromise({
|
|
6110
|
-
try: () => this.#client.action(fn, args),
|
|
6111
|
-
catch: (cause) => mapToConvexCallError(
|
|
6251
|
+
try: () => this.#client.action(fn, this.#observedActionArgs(path, args)),
|
|
6252
|
+
catch: (cause) => mapToConvexCallError(path, cause)
|
|
6253
|
+
});
|
|
6254
|
+
}
|
|
6255
|
+
#observedActionArgs(path, args) {
|
|
6256
|
+
if (!OBSERVED_CONVEX_ACTIONS.has(path)) return args;
|
|
6257
|
+
let hostContext;
|
|
6258
|
+
const invocationSnapshot = readInvocationObservation(args);
|
|
6259
|
+
if (invocationSnapshot !== void 0) hostContext = invocationSnapshot.context;
|
|
6260
|
+
else {
|
|
6261
|
+
const resolveContext = this.#observation?.resolveContext;
|
|
6262
|
+
if (resolveContext === void 0) return args;
|
|
6263
|
+
try {
|
|
6264
|
+
hostContext = resolveContext();
|
|
6265
|
+
} catch {
|
|
6266
|
+
return args;
|
|
6267
|
+
}
|
|
6268
|
+
}
|
|
6269
|
+
if (hostContext === void 0) return args;
|
|
6270
|
+
hostContext = sanitizeObservationContext({
|
|
6271
|
+
...hostContext,
|
|
6272
|
+
...this.#applicationId === void 0 ? {} : { applicationId: this.#applicationId }
|
|
6112
6273
|
});
|
|
6274
|
+
if (hostContext === void 0) return args;
|
|
6275
|
+
return {
|
|
6276
|
+
...args,
|
|
6277
|
+
observationContext: hostContext
|
|
6278
|
+
};
|
|
6113
6279
|
}
|
|
6114
6280
|
subscribe(fn, args, callback) {
|
|
6115
6281
|
return Effect.try({
|
|
@@ -6777,7 +6943,7 @@ function fromWei(rawBalance, decimals, currency) {
|
|
|
6777
6943
|
}
|
|
6778
6944
|
//#endregion
|
|
6779
6945
|
//#region ../../packages/sdk/src/adapters/account-read/ConvexAccountAdapter.ts
|
|
6780
|
-
const DEFAULT_FUNCTIONS$
|
|
6946
|
+
const DEFAULT_FUNCTIONS$5 = {
|
|
6781
6947
|
readBalance: makeFunctionReference("account/actions:readBalance"),
|
|
6782
6948
|
faucetMint: makeFunctionReference("account/actions:faucetMint")
|
|
6783
6949
|
};
|
|
@@ -6786,7 +6952,7 @@ var ConvexAccountAdapter = class {
|
|
|
6786
6952
|
#fns;
|
|
6787
6953
|
constructor(deps) {
|
|
6788
6954
|
this.#convex = deps.convex;
|
|
6789
|
-
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$
|
|
6955
|
+
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$5;
|
|
6790
6956
|
}
|
|
6791
6957
|
readBalance(input) {
|
|
6792
6958
|
return this.#convex.action(this.#fns.readBalance, { chainId: wireChainId(input.chainId) }).pipe(Effect.mapError((error) => accountReadErrorFromCapxul("readBalance", error.publicError, error)), Effect.flatMap((wire) => brandAccountEffect("readBalance", wire)), Effect.catchAllDefect((cause) => Effect.fail(accountReadErrorFromUnknown("readBalance", cause))));
|
|
@@ -6839,7 +7005,7 @@ function subAccountErrorFromCapxul(operation, error, cause = error) {
|
|
|
6839
7005
|
var SubAccountPortTag = class extends Context.Tag("@capxul/sdk/ports/SubAccountPort")() {};
|
|
6840
7006
|
//#endregion
|
|
6841
7007
|
//#region ../../packages/sdk/src/adapters/sub-account/ConvexSubAccountAdapter.ts
|
|
6842
|
-
const DEFAULT_FUNCTIONS$
|
|
7008
|
+
const DEFAULT_FUNCTIONS$4 = {
|
|
6843
7009
|
create: makeFunctionReference("subAccount/mutations:create"),
|
|
6844
7010
|
get: makeFunctionReference("subAccount/queries:get"),
|
|
6845
7011
|
list: makeFunctionReference("subAccount/queries:list"),
|
|
@@ -6854,7 +7020,7 @@ var ConvexSubAccountAdapter = class {
|
|
|
6854
7020
|
constructor(deps) {
|
|
6855
7021
|
this.#convex = deps.convex;
|
|
6856
7022
|
this.#chainId = deps.chainId;
|
|
6857
|
-
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$
|
|
7023
|
+
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$4;
|
|
6858
7024
|
}
|
|
6859
7025
|
create(input) {
|
|
6860
7026
|
return this.#runMutation("create", this.#fns.create, {
|
|
@@ -6882,12 +7048,12 @@ var ConvexSubAccountAdapter = class {
|
|
|
6882
7048
|
const operation = "transfer";
|
|
6883
7049
|
return Effect.suspend(() => {
|
|
6884
7050
|
const rawAmount = toWei(input.amount);
|
|
6885
|
-
return this.#convex.action(this.#fns.transfer, {
|
|
7051
|
+
return this.#convex.action(this.#fns.transfer, copyInvocationObservation(input, {
|
|
6886
7052
|
chainId: this.#chainId,
|
|
6887
7053
|
from: input.from,
|
|
6888
7054
|
to: input.to,
|
|
6889
7055
|
rawAmount
|
|
6890
|
-
});
|
|
7056
|
+
}));
|
|
6891
7057
|
}).pipe(Effect.mapError((error) => subAccountErrorFromCapxul(operation, error.publicError, error)), Effect.map((wire) => brandTransferResult(wire)), Effect.catchAllDefect((cause) => Effect.fail(subAccountErrorFromUnknown(operation, cause))));
|
|
6892
7058
|
}
|
|
6893
7059
|
#runMutation(operation, ref, args) {
|
|
@@ -6938,7 +7104,7 @@ function smartAccountErrorFromCapxul(operation, error, cause = error) {
|
|
|
6938
7104
|
var SmartAccountPortTag = class extends Context.Tag("@capxul/sdk/ports/SmartAccountPort")() {};
|
|
6939
7105
|
//#endregion
|
|
6940
7106
|
//#region ../../packages/sdk/src/adapters/smart-account/ConvexSmartAccountAdapter.ts
|
|
6941
|
-
const DEFAULT_FUNCTIONS$
|
|
7107
|
+
const DEFAULT_FUNCTIONS$3 = {
|
|
6942
7108
|
loadByAuthUserId: makeFunctionReference("smartAccount/queries:loadByAuthUserId"),
|
|
6943
7109
|
loadBySmartAccountAddress: makeFunctionReference("smartAccount/queries:loadBySmartAccountAddress"),
|
|
6944
7110
|
provision: makeFunctionReference("smartAccount/mutations:provision"),
|
|
@@ -6950,7 +7116,7 @@ var ConvexSmartAccountAdapter = class {
|
|
|
6950
7116
|
#fns;
|
|
6951
7117
|
constructor(deps) {
|
|
6952
7118
|
this.#convex = deps.convex;
|
|
6953
|
-
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$
|
|
7119
|
+
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$3;
|
|
6954
7120
|
}
|
|
6955
7121
|
loadByAuthUserId(authUserId) {
|
|
6956
7122
|
return this.#convex.query(this.#fns.loadByAuthUserId, { authUserId }).pipe(Effect.mapError((error) => smartAccountErrorFromCapxul("loadByAuthUserId", error.publicError, error)), Effect.flatMap((row) => brandSmartAccountEffect("loadByAuthUserId", row)), Effect.catchAllDefect((cause) => Effect.fail(smartAccountErrorFromUnknown("loadByAuthUserId", cause))));
|
|
@@ -7025,100 +7191,518 @@ function smartAccountErrorFromUnknown(operation, cause) {
|
|
|
7025
7191
|
toAddress("0xa6b71e26c5e0845f74c812102ca7114b6a896ab2");
|
|
7026
7192
|
keccak256("0x");
|
|
7027
7193
|
//#endregion
|
|
7028
|
-
//#region ../../packages/
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
|
|
7038
|
-
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
|
|
7061
|
-
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7194
|
+
//#region ../../packages/sdk/src/ports/org.ts
|
|
7195
|
+
var OrgError = class extends Data.TaggedError("OrgError") {};
|
|
7196
|
+
function orgErrorFromCapxul(operation, error, cause = error) {
|
|
7197
|
+
return new OrgError({
|
|
7198
|
+
operation,
|
|
7199
|
+
publicCode: error.code,
|
|
7200
|
+
publicError: error,
|
|
7201
|
+
cause,
|
|
7202
|
+
...error.details === void 0 ? {} : { details: error.details }
|
|
7203
|
+
});
|
|
7204
|
+
}
|
|
7205
|
+
Context.Tag("@capxul/sdk/ports/OrgPort")();
|
|
7206
|
+
Context.Tag("@capxul/sdk/ports/OrgRolesDeploymentPort")();
|
|
7207
|
+
Context.Tag("@capxul/sdk/ports/OrgSpendPort")();
|
|
7208
|
+
//#endregion
|
|
7209
|
+
//#region ../../packages/sdk/src/adapters/org/parse.ts
|
|
7210
|
+
/**
|
|
7211
|
+
* Map a `WireOrg` + its (separately read) treasury `Account` into the branded
|
|
7212
|
+
* `OrgView`. The viewer role is projected by the authenticated backend read;
|
|
7213
|
+
* it must never be inferred from Organization ownership. Brands at the read
|
|
7214
|
+
* edge: `orgId`, `safeAddress`.
|
|
7215
|
+
*/
|
|
7216
|
+
function brandOrgView(wire, treasury, viewerRole) {
|
|
7217
|
+
return {
|
|
7218
|
+
id: toOrgId(wire.orgId),
|
|
7219
|
+
name: wire.name,
|
|
7220
|
+
handle: wire.slug,
|
|
7221
|
+
safeAddress: toAddress(wire.safeAddress.toLowerCase()),
|
|
7222
|
+
role: viewerRole,
|
|
7223
|
+
treasury
|
|
7224
|
+
};
|
|
7225
|
+
}
|
|
7226
|
+
/**
|
|
7227
|
+
* Build the Org treasury `Account` from the raw on-chain `balanceOf` integer
|
|
7228
|
+
* (the D3 RPC read). `available === balance` for a treasury with no envelope
|
|
7229
|
+
* partition yet (a fresh Org reads back $0).
|
|
7230
|
+
*/
|
|
7231
|
+
function brandOrgTreasury(input) {
|
|
7232
|
+
return {
|
|
7233
|
+
id: toAccountId(`account_${orgIdBody(input.orgId)}`),
|
|
7234
|
+
balance: input.money,
|
|
7235
|
+
available: input.money
|
|
7236
|
+
};
|
|
7237
|
+
}
|
|
7238
|
+
function brandOrgRole(wire) {
|
|
7239
|
+
return {
|
|
7240
|
+
orgId: toOrgId(wire.orgId),
|
|
7241
|
+
label: wire.label,
|
|
7242
|
+
roleKey: toRoleKey(wire.roleKey),
|
|
7243
|
+
definition: parseRoleDefinition(wire.definitionJson)
|
|
7244
|
+
};
|
|
7245
|
+
}
|
|
7246
|
+
function brandOrgMember(wire) {
|
|
7247
|
+
return {
|
|
7248
|
+
orgId: toOrgId(wire.orgId),
|
|
7249
|
+
email: toEmail(wire.email),
|
|
7250
|
+
name: wire.name,
|
|
7251
|
+
personalSafeAddress: wire.personalSafeAddress === null ? null : toAddress(wire.personalSafeAddress),
|
|
7252
|
+
role: wire.role,
|
|
7253
|
+
roleKey: wire.roleKey === null ? null : toRoleKey(wire.roleKey),
|
|
7254
|
+
status: wire.status,
|
|
7255
|
+
grantTxHash: wire.grantTxHash,
|
|
7256
|
+
revokeTxHash: wire.revokeTxHash
|
|
7257
|
+
};
|
|
7258
|
+
}
|
|
7259
|
+
function parseRoleDefinition(json) {
|
|
7260
|
+
let raw;
|
|
7261
|
+
try {
|
|
7262
|
+
const parsed = JSON.parse(json);
|
|
7263
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error("expected object");
|
|
7264
|
+
raw = parsed;
|
|
7265
|
+
} catch (err) {
|
|
7266
|
+
throw new Error(`Invalid role definition: malformed JSON - ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
7267
|
+
}
|
|
7268
|
+
if (typeof raw.label !== "string" || raw.label.trim().length === 0) throw new Error("Invalid role definition: missing label");
|
|
7269
|
+
return {
|
|
7270
|
+
label: raw.label,
|
|
7271
|
+
...raw.spend === void 0 ? {} : { spend: {
|
|
7272
|
+
...raw.spend.perTx === void 0 ? {} : { perTx: parseRoleMoney(raw.spend.perTx, "perTx") },
|
|
7273
|
+
...raw.spend.perDay === void 0 ? {} : { perDay: parseRoleMoney(raw.spend.perDay, "perDay") },
|
|
7274
|
+
...raw.spend.toRecipients === void 0 ? {} : { toRecipients: parseRoleRecipients(raw.spend.toRecipients) }
|
|
7275
|
+
} },
|
|
7276
|
+
...raw.subAccounts === void 0 ? {} : { subAccounts: parseRoleSubAccounts(raw.subAccounts) },
|
|
7277
|
+
...typeof raw.canManageMembers === "boolean" ? { canManageMembers: raw.canManageMembers } : {},
|
|
7278
|
+
...typeof raw.canManageRoles === "boolean" ? { canManageRoles: raw.canManageRoles } : {}
|
|
7279
|
+
};
|
|
7280
|
+
}
|
|
7281
|
+
function parseRoleMoney(raw, field) {
|
|
7282
|
+
if (typeof raw.currency !== "string" || typeof raw.value !== "string" || !/^\d+$/.test(raw.value) || raw.decimals !== 6) throw new Error(`Invalid role money: ${field}`);
|
|
7283
|
+
return {
|
|
7284
|
+
currency: toCurrencyCode(raw.currency),
|
|
7285
|
+
value: raw.value,
|
|
7286
|
+
decimals: raw.decimals
|
|
7287
|
+
};
|
|
7288
|
+
}
|
|
7289
|
+
function parseRoleRecipients(raw) {
|
|
7290
|
+
if (raw === "anyone") return "anyone";
|
|
7291
|
+
if (!Array.isArray(raw)) throw new Error("Invalid role definition: toRecipients must be \"anyone\" or an array");
|
|
7292
|
+
return raw.map((recipient) => {
|
|
7293
|
+
if (typeof recipient !== "string") throw new Error("Invalid role definition: toRecipients must be \"anyone\" or an array");
|
|
7294
|
+
return toAddress(recipient);
|
|
7295
|
+
});
|
|
7296
|
+
}
|
|
7297
|
+
function parseRoleSubAccounts(raw) {
|
|
7298
|
+
if (raw.scope === "all") return { scope: "all" };
|
|
7299
|
+
if (!Array.isArray(raw.scope)) throw new Error("Invalid role definition: subAccounts.scope must be \"all\" or an array");
|
|
7300
|
+
return { scope: raw.scope.map((subAccountId) => {
|
|
7301
|
+
if (typeof subAccountId !== "string") throw new Error("Invalid role definition: subAccounts.scope must be \"all\" or an array");
|
|
7302
|
+
return toSubAccountId(subAccountId);
|
|
7303
|
+
}) };
|
|
7304
|
+
}
|
|
7305
|
+
/** Strip the `org_` prefix + non-alphanumerics so the body re-seeds `account_`. */
|
|
7306
|
+
function orgIdBody(orgId) {
|
|
7307
|
+
const underscore = orgId.indexOf("_");
|
|
7308
|
+
const cleaned = (underscore < 0 ? orgId : orgId.slice(underscore + 1)).replace(/[^0-9A-Za-z]/g, "");
|
|
7309
|
+
return cleaned.length > 0 ? cleaned : "0";
|
|
7310
|
+
}
|
|
7311
|
+
//#endregion
|
|
7312
|
+
//#region ../../packages/sdk/src/adapters/org/ConvexOrganizationAdapter.ts
|
|
7313
|
+
const DEFAULT_FUNCTIONS$2 = {
|
|
7314
|
+
listAll: makeFunctionReference("org/queries:listAll"),
|
|
7315
|
+
listRoles: makeFunctionReference("org/queries:listRolesByOrgId"),
|
|
7316
|
+
listMembers: makeFunctionReference("org/queries:listMembersByOrgId"),
|
|
7317
|
+
readTreasury: makeFunctionReference("org/actions:readTreasury"),
|
|
7318
|
+
inviteMember: makeFunctionReference("org/actions:inviteMember"),
|
|
7319
|
+
resendInvite: makeFunctionReference("org/mutations:resendInviteToken"),
|
|
7320
|
+
detectInvitations: makeFunctionReference("org/actions:detectAndAcceptPendingInvitations")
|
|
7079
7321
|
};
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
}
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
})
|
|
7097
|
-
const
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
}
|
|
7112
|
-
|
|
7113
|
-
|
|
7114
|
-
|
|
7115
|
-
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7322
|
+
/**
|
|
7323
|
+
* Standard production Organization read adapter. It intentionally has no
|
|
7324
|
+
* deployer/RPC/test configuration: authenticated Convex actions own live chain
|
|
7325
|
+
* reads, while the lifecycle adapter owns the single sponsored bootstrap.
|
|
7326
|
+
*/
|
|
7327
|
+
var ConvexOrganizationAdapter = class {
|
|
7328
|
+
#convex;
|
|
7329
|
+
#fns;
|
|
7330
|
+
constructor(input) {
|
|
7331
|
+
this.#convex = input.convex;
|
|
7332
|
+
this.#fns = input.functions ?? DEFAULT_FUNCTIONS$2;
|
|
7333
|
+
}
|
|
7334
|
+
createOrg(_input) {
|
|
7335
|
+
return Effect.fail(orgErrorFromCapxul("createOrg", Errors.notImplemented("organizationSetup", "use onboarding.completeOrganization")));
|
|
7336
|
+
}
|
|
7337
|
+
listOrgs(_input) {
|
|
7338
|
+
return this.#convex.query(this.#fns.listAll, {}).pipe(Effect.mapError((error) => orgErrorFromCapxul("listOrgs", error.publicError, error)), Effect.flatMap((wires) => Effect.forEach(wires, (wire) => this.#readTreasuryWire(wire.orgId).pipe(Effect.map((treasury) => {
|
|
7339
|
+
const viewerRole = wire.viewerRole.trim();
|
|
7340
|
+
if (viewerRole.length === 0) throw Errors.wrongState({
|
|
7341
|
+
method: "listOrgs",
|
|
7342
|
+
currentState: "viewerRoleMissing",
|
|
7343
|
+
validStates: ["activeViewerRole"]
|
|
7344
|
+
});
|
|
7345
|
+
return brandOrgView(wire, treasury, viewerRole);
|
|
7346
|
+
})))), Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("listOrgs", cause))));
|
|
7347
|
+
}
|
|
7348
|
+
readTreasury(input) {
|
|
7349
|
+
return this.#readTreasuryWire(String(input.orgId)).pipe(Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("readTreasury", cause))));
|
|
7350
|
+
}
|
|
7351
|
+
listRoles(input) {
|
|
7352
|
+
return this.#convex.query(this.#fns.listRoles, { orgId: input.orgId }).pipe(Effect.mapError((error) => orgErrorFromCapxul("listRoles", error.publicError, error)), Effect.flatMap((rows) => rows.length === 0 ? Effect.fail(partialOrgTruth("listRoles", "activeRoleMissing")) : Effect.succeed(rows.map(brandOrgRole))), Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("listRoles", cause))));
|
|
7353
|
+
}
|
|
7354
|
+
listMembers(input) {
|
|
7355
|
+
return this.#convex.query(this.#fns.listMembers, { orgId: input.orgId }).pipe(Effect.mapError((error) => orgErrorFromCapxul("listMembers", error.publicError, error)), Effect.flatMap((rows) => rows.length === 0 ? Effect.fail(partialOrgTruth("listMembers", "activeMemberMissing")) : Effect.succeed(rows.map(brandOrgMember))), Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("listMembers", cause))));
|
|
7356
|
+
}
|
|
7357
|
+
pendingMembers(input) {
|
|
7358
|
+
return this.listMembers(input).pipe(Effect.map((members) => members.filter((member) => member.status === "pending" || member.status === "pending_safe" || member.status === "pending_grant")));
|
|
7359
|
+
}
|
|
7360
|
+
inviteMember(input) {
|
|
7361
|
+
return this.#convex.action(this.#fns.inviteMember, {
|
|
7362
|
+
orgId: input.orgId,
|
|
7363
|
+
email: input.input.email,
|
|
7364
|
+
role: input.input.role
|
|
7365
|
+
}).pipe(Effect.mapError((error) => orgErrorFromCapxul("inviteMember", error.publicError, error)), Effect.map(brandOrgMember), Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("inviteMember", cause))));
|
|
7366
|
+
}
|
|
7367
|
+
resendInviteToken(input) {
|
|
7368
|
+
return this.#convex.mutation(this.#fns.resendInvite, {
|
|
7369
|
+
orgId: input.orgId,
|
|
7370
|
+
email: input.email
|
|
7371
|
+
}).pipe(Effect.mapError((error) => orgErrorFromCapxul("resendInviteToken", error.publicError, error)), Effect.map(brandOrgMember), Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("resendInviteToken", cause))));
|
|
7372
|
+
}
|
|
7373
|
+
detectAndAcceptPendingInvitations(_input) {
|
|
7374
|
+
return this.#convex.action(this.#fns.detectInvitations, {}).pipe(Effect.mapError((error) => orgErrorFromCapxul("detectAndAcceptPendingInvitations", error.publicError, error)), Effect.map((result) => ({ matched: result.matched.map(toOrgId) })), Effect.catchAllDefect((cause) => Effect.fail(toOrgError$1("detectAndAcceptPendingInvitations", cause))));
|
|
7375
|
+
}
|
|
7376
|
+
#readTreasuryWire(orgId) {
|
|
7377
|
+
return this.#convex.action(this.#fns.readTreasury, { orgId }).pipe(Effect.mapError((error) => orgErrorFromCapxul("readTreasury", error.publicError, error)), Effect.map((wire) => {
|
|
7378
|
+
if (wire.orgId !== orgId) throw Errors.invalidInput("orgId", "Organization treasury scope does not match");
|
|
7379
|
+
const balance = fromWei(wire.rawBalance, wire.decimals, wire.currency);
|
|
7380
|
+
const available = fromWei(wire.rawAvailableBalance, wire.decimals, wire.currency);
|
|
7381
|
+
return {
|
|
7382
|
+
...brandOrgTreasury({
|
|
7383
|
+
orgId: wire.orgId,
|
|
7384
|
+
money: balance
|
|
7385
|
+
}),
|
|
7386
|
+
available
|
|
7387
|
+
};
|
|
7388
|
+
}));
|
|
7389
|
+
}
|
|
7390
|
+
};
|
|
7391
|
+
function toOrgError$1(operation, cause) {
|
|
7392
|
+
if (cause instanceof CapxulError) return orgErrorFromCapxul(operation, cause);
|
|
7393
|
+
return orgErrorFromCapxul(operation, Errors.providerError("convex", operation, cause), cause);
|
|
7394
|
+
}
|
|
7395
|
+
function partialOrgTruth(operation, currentState) {
|
|
7396
|
+
return orgErrorFromCapxul(operation, Errors.wrongState({
|
|
7397
|
+
method: operation,
|
|
7398
|
+
currentState,
|
|
7399
|
+
validStates: ["completeProductionOrganizationTruth"]
|
|
7400
|
+
}));
|
|
7401
|
+
}
|
|
7402
|
+
//#endregion
|
|
7403
|
+
//#region ../../packages/sdk/src/adapters/org/ConvexOrganizationSetupAdapter.ts
|
|
7404
|
+
const DEFAULT_FUNCTIONS$1 = {
|
|
7405
|
+
startOrResume: makeFunctionReference("org/lifecycle:startOrResume"),
|
|
7406
|
+
prepareFounderAccount: makeFunctionReference("org/actions:prepareFounderAccount"),
|
|
7407
|
+
prepareBootstrap: makeFunctionReference("org/actions:prepareBootstrap"),
|
|
7408
|
+
submitBootstrap: makeFunctionReference("org/actions:submitBootstrap"),
|
|
7409
|
+
confirmBootstrap: makeFunctionReference("org/actions:confirmBootstrap"),
|
|
7410
|
+
recordFailure: makeFunctionReference("org/lifecycle:recordFailure"),
|
|
7411
|
+
load: makeFunctionReference("org/lifecycle:load"),
|
|
7412
|
+
retry: makeFunctionReference("org/lifecycle:retry")
|
|
7413
|
+
};
|
|
7414
|
+
/** Durable Organization setup capability composed by the standard client. */
|
|
7415
|
+
var ConvexOrganizationSetupAdapter = class {
|
|
7416
|
+
#convex;
|
|
7417
|
+
#signer;
|
|
7418
|
+
#fns;
|
|
7419
|
+
constructor(input) {
|
|
7420
|
+
this.#convex = input.convex;
|
|
7421
|
+
this.#signer = input.signer;
|
|
7422
|
+
this.#fns = input.functions ?? DEFAULT_FUNCTIONS$1;
|
|
7423
|
+
}
|
|
7424
|
+
async startOrResume(input) {
|
|
7425
|
+
const result = await runCall("startOrResume", this.#convex.mutation(this.#fns.startOrResume, input));
|
|
7426
|
+
if (!result.ok) return result;
|
|
7427
|
+
const lifecycle = parseLifecycle("startOrResume", result.value.lifecycle);
|
|
7428
|
+
if (!lifecycle.ok) return lifecycle;
|
|
7429
|
+
const orgId = parseOrgId("startOrResume", result.value.orgId);
|
|
7430
|
+
if (!orgId.ok) return orgId;
|
|
7431
|
+
if (String(orgId.value) !== String(lifecycle.value.orgId)) return fail$2(Errors.invalidInput("orgId", "Organization lifecycle scope does not match"));
|
|
7432
|
+
return {
|
|
7433
|
+
ok: true,
|
|
7434
|
+
value: {
|
|
7435
|
+
orgId: orgId.value,
|
|
7436
|
+
lifecycle: lifecycle.value
|
|
7437
|
+
}
|
|
7438
|
+
};
|
|
7439
|
+
}
|
|
7440
|
+
prepareFounderAccount(input) {
|
|
7441
|
+
return this.#lifecycleAction("prepareFounderAccount", input, () => this.#convex.action(this.#fns.prepareFounderAccount, { orgId: input.orgId }));
|
|
7442
|
+
}
|
|
7443
|
+
async authorizeAndSubmitBootstrap(input) {
|
|
7444
|
+
const cancelled = cancellation(input.signal);
|
|
7445
|
+
if (cancelled !== void 0) return cancelled;
|
|
7446
|
+
const signerAddress = await signerResult("getAddress", () => this.#signer.getAddress());
|
|
7447
|
+
if (!signerAddress.ok) return signerAddress;
|
|
7448
|
+
const prepared = await runCall("prepareBootstrap", this.#convex.action(this.#fns.prepareBootstrap, {
|
|
7449
|
+
orgId: input.orgId,
|
|
7450
|
+
signerAddress: signerAddress.value
|
|
7451
|
+
}));
|
|
7452
|
+
if (!prepared.ok) return prepared;
|
|
7453
|
+
const authority = validatePreparedAuthorities(prepared.value, signerAddress.value);
|
|
7454
|
+
if (!authority.ok) return authority;
|
|
7455
|
+
const cancelledAfterPrepare = cancellation(input.signal);
|
|
7456
|
+
if (cancelledAfterPrepare !== void 0) return cancelledAfterPrepare;
|
|
7457
|
+
const signature = await signerResult("signUserOpHash", () => this.#signer.signUserOpHash(prepared.value.digest));
|
|
7458
|
+
if (!signature.ok) return signature;
|
|
7459
|
+
const cancelledAfterSign = cancellation(input.signal);
|
|
7460
|
+
if (cancelledAfterSign !== void 0) return cancelledAfterSign;
|
|
7461
|
+
const submitted = await runCall("submitBootstrap", this.#convex.action(this.#fns.submitBootstrap, {
|
|
7462
|
+
orgId: input.orgId,
|
|
7463
|
+
signerAddress: signerAddress.value,
|
|
7464
|
+
signature: signature.value,
|
|
7465
|
+
userOp: prepared.value.userOp
|
|
7466
|
+
}));
|
|
7467
|
+
if (!submitted.ok) return submitted;
|
|
7468
|
+
return parseLifecycle("submitBootstrap", submitted.value);
|
|
7469
|
+
}
|
|
7470
|
+
confirmSubmittedBootstrap(input) {
|
|
7471
|
+
return this.#lifecycleAction("confirmBootstrap", input, () => this.#convex.action(this.#fns.confirmBootstrap, { orgId: input.orgId }));
|
|
7472
|
+
}
|
|
7473
|
+
async recordFailure(input) {
|
|
7474
|
+
const result = await runCall("recordFailure", this.#convex.mutation(this.#fns.recordFailure, {
|
|
7475
|
+
orgId: input.orgId,
|
|
7476
|
+
at: input.at,
|
|
7477
|
+
errorCode: input.error.code,
|
|
7478
|
+
retryable: input.retryable
|
|
7479
|
+
}));
|
|
7480
|
+
return result.ok ? parseLifecycle("recordFailure", result.value) : result;
|
|
7481
|
+
}
|
|
7482
|
+
async loadLifecycle(input) {
|
|
7483
|
+
const result = await runCall("loadLifecycle", this.#convex.query(this.#fns.load, input));
|
|
7484
|
+
if (!result.ok) return result;
|
|
7485
|
+
if (result.value === null) return fail$2(Errors.invalidInput("orgId", "Organization lifecycle was not found"));
|
|
7486
|
+
return parseLifecycle("loadLifecycle", result.value);
|
|
7487
|
+
}
|
|
7488
|
+
async retry(input) {
|
|
7489
|
+
const cancelled = cancellation(input.signal);
|
|
7490
|
+
if (cancelled !== void 0) return cancelled;
|
|
7491
|
+
const result = await runCall("retry", this.#convex.mutation(this.#fns.retry, { orgId: input.orgId }));
|
|
7492
|
+
return result.ok ? parseLifecycle("retry", result.value) : result;
|
|
7493
|
+
}
|
|
7494
|
+
async #lifecycleAction(operation, input, call) {
|
|
7495
|
+
const cancelled = cancellation(input.signal);
|
|
7496
|
+
if (cancelled !== void 0) return cancelled;
|
|
7497
|
+
const result = await runCall(operation, call());
|
|
7498
|
+
if (!result.ok) return result;
|
|
7499
|
+
const cancelledAfter = cancellation(input.signal);
|
|
7500
|
+
if (cancelledAfter !== void 0) return cancelledAfter;
|
|
7501
|
+
return parseLifecycle(operation, result.value);
|
|
7502
|
+
}
|
|
7503
|
+
};
|
|
7504
|
+
async function runCall(operation, effect) {
|
|
7505
|
+
try {
|
|
7506
|
+
const result = await Effect.runPromise(Effect.either(effect));
|
|
7507
|
+
return Either.isRight(result) ? {
|
|
7508
|
+
ok: true,
|
|
7509
|
+
value: result.right
|
|
7510
|
+
} : fail$2(publicError(operation, result.left));
|
|
7511
|
+
} catch (cause) {
|
|
7512
|
+
return fail$2(publicError(operation, cause));
|
|
7513
|
+
}
|
|
7514
|
+
}
|
|
7515
|
+
function publicError(operation, cause) {
|
|
7516
|
+
if (cause instanceof CapxulError) return cause;
|
|
7517
|
+
if (typeof cause === "object" && cause !== null) {
|
|
7518
|
+
const carried = cause.publicError;
|
|
7519
|
+
if (carried instanceof CapxulError) return carried;
|
|
7520
|
+
}
|
|
7521
|
+
return Errors.providerError("convex-organization", operation, cause);
|
|
7522
|
+
}
|
|
7523
|
+
async function signerResult(operation, run) {
|
|
7524
|
+
try {
|
|
7525
|
+
return {
|
|
7526
|
+
ok: true,
|
|
7527
|
+
value: await run()
|
|
7528
|
+
};
|
|
7529
|
+
} catch (cause) {
|
|
7530
|
+
return fail$2(Errors.providerError("organization-signer", operation, cause));
|
|
7531
|
+
}
|
|
7532
|
+
}
|
|
7533
|
+
function validatePreparedAuthorities(prepared, signerAddress) {
|
|
7534
|
+
const signer = signerAddress.toLowerCase();
|
|
7535
|
+
const preparedSigner = prepared.signerAddress.toLowerCase();
|
|
7536
|
+
const founder = prepared.founderPersonalAccount.toLowerCase();
|
|
7537
|
+
const organization = prepared.organizationAccountAddress.toLowerCase();
|
|
7538
|
+
const sender = prepared.userOp.sender.toLowerCase();
|
|
7539
|
+
if (preparedSigner !== signer) return fail$2(Errors.invalidInput("signerAddress", "Prepared signer does not match configured signer"));
|
|
7540
|
+
if (founder === signer || organization === signer || organization === founder) return fail$2(Errors.invalidInput("organizationAuthority", "Signer EOA, founder Account, and Organization Account must be distinct"));
|
|
7541
|
+
if (sender !== founder) return fail$2(Errors.invalidInput("userOp.sender", "Bootstrap sender must be the founder Account"));
|
|
7542
|
+
if (!/^0x[0-9a-fA-F]{64}$/u.test(prepared.digest)) return fail$2(Errors.invalidInput("digest", "Prepared bootstrap digest must be 32-byte hex"));
|
|
7543
|
+
return {
|
|
7544
|
+
ok: true,
|
|
7545
|
+
value: void 0
|
|
7546
|
+
};
|
|
7547
|
+
}
|
|
7548
|
+
function parseLifecycle(operation, wire) {
|
|
7549
|
+
const orgId = parseOrgId(operation, wire.orgId);
|
|
7550
|
+
if (!orgId.ok) return orgId;
|
|
7551
|
+
if (wire.status === "loading") return {
|
|
7552
|
+
ok: true,
|
|
7553
|
+
value: {
|
|
7554
|
+
status: "loading",
|
|
7555
|
+
orgId: orgId.value
|
|
7556
|
+
}
|
|
7557
|
+
};
|
|
7558
|
+
if (wire.status === "ready") return {
|
|
7559
|
+
ok: true,
|
|
7560
|
+
value: {
|
|
7561
|
+
status: "ready",
|
|
7562
|
+
orgId: orgId.value,
|
|
7563
|
+
canTransact: true
|
|
7564
|
+
}
|
|
7565
|
+
};
|
|
7566
|
+
if (wire.status === "failed") {
|
|
7567
|
+
if (!isSetupStep(wire.at)) return fail$2(Errors.invalidInput("lifecycle.at", "Unknown setup step"));
|
|
7568
|
+
return {
|
|
7569
|
+
ok: true,
|
|
7570
|
+
value: {
|
|
7571
|
+
status: "failed",
|
|
7572
|
+
orgId: orgId.value,
|
|
7573
|
+
at: wire.at,
|
|
7574
|
+
error: new CapxulError(wire.error.code, wire.error.message),
|
|
7575
|
+
retryable: wire.retryable
|
|
7576
|
+
}
|
|
7577
|
+
};
|
|
7578
|
+
}
|
|
7579
|
+
if (!isSetupStep(wire.step)) return fail$2(Errors.invalidInput("lifecycle.step", `Unknown setup step from ${operation}`));
|
|
7580
|
+
return {
|
|
7581
|
+
ok: true,
|
|
7582
|
+
value: {
|
|
7583
|
+
status: "settingUp",
|
|
7584
|
+
orgId: orgId.value,
|
|
7585
|
+
step: wire.step
|
|
7586
|
+
}
|
|
7587
|
+
};
|
|
7588
|
+
}
|
|
7589
|
+
function parseOrgId(operation, value) {
|
|
7590
|
+
try {
|
|
7591
|
+
return {
|
|
7592
|
+
ok: true,
|
|
7593
|
+
value: toOrgId(value)
|
|
7594
|
+
};
|
|
7595
|
+
} catch (cause) {
|
|
7596
|
+
return fail$2(Errors.providerError("convex-organization", operation, cause));
|
|
7597
|
+
}
|
|
7598
|
+
}
|
|
7599
|
+
function isSetupStep(value) {
|
|
7600
|
+
return value === "preparingFounderAccount" || value === "awaitingFounderAuthorization" || value === "submittingBootstrap" || value === "confirmingBootstrap";
|
|
7601
|
+
}
|
|
7602
|
+
function cancellation(signal) {
|
|
7603
|
+
return signal?.aborted ? fail$2(Errors.cancelled({ operation: "organization.setup" })) : void 0;
|
|
7604
|
+
}
|
|
7605
|
+
function fail$2(error) {
|
|
7606
|
+
return {
|
|
7607
|
+
ok: false,
|
|
7608
|
+
error
|
|
7609
|
+
};
|
|
7610
|
+
}
|
|
7611
|
+
//#endregion
|
|
7612
|
+
//#region ../../packages/observability/src/index.ts
|
|
7613
|
+
const PII = Schema.String.pipe(Schema.brand("PII"));
|
|
7614
|
+
const OptionalString = Schema.optional(Schema.String);
|
|
7615
|
+
const AddressSchema = Schema.String.pipe(Schema.transform(Schema.String, {
|
|
7616
|
+
decode: (value) => value.toLowerCase(),
|
|
7617
|
+
encode: (value) => value
|
|
7618
|
+
}), Schema.filter((value) => EVM_ADDRESS_RE$1.test(value), { message: () => "must be 0x + 40 hex chars" }));
|
|
7619
|
+
const AppIdSchema = Schema.String.pipe(Schema.filter((value) => APP_ID_RE.test(value), { message: () => "must be app_ plus a ULID" }));
|
|
7620
|
+
const BlockNumberSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value >= 0, { message: () => "must be a non-negative safe integer" }));
|
|
7621
|
+
const ChainIdSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value > 0, { message: () => "must be a positive safe integer" }));
|
|
7622
|
+
const DurationMsSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value >= 0, { message: () => "must be a non-negative safe integer" }));
|
|
7623
|
+
const EpochMsSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value >= 0, { message: () => "must be a non-negative safe integer" }));
|
|
7624
|
+
const PublishableKeyIdSchema = Schema.String.pipe(Schema.filter((value) => value.length > 0, { message: () => "must be a non-empty string" }));
|
|
7625
|
+
const TxHashSchema = Schema.String.pipe(Schema.filter((value) => BYTES32_RE$2.test(value), { message: () => "must be 0x + 64 hex chars" }));
|
|
7626
|
+
const ACCOUNT_ID_TELEMETRY_RE = /^account_[0-9A-Za-z]+$/;
|
|
7627
|
+
const SUBACCOUNT_ID_TELEMETRY_RE = /^subaccount_[0-9A-Za-z]+$/;
|
|
7628
|
+
const WEI_AMOUNT_TELEMETRY_RE = /^[0-9]+$/;
|
|
7629
|
+
const AccountIdSchema = Schema.String.pipe(Schema.filter((value) => ACCOUNT_ID_TELEMETRY_RE.test(value), { message: () => "must be account_ plus an alphanumeric id" }));
|
|
7630
|
+
const SubAccountIdSchema = Schema.String.pipe(Schema.filter((value) => SUBACCOUNT_ID_TELEMETRY_RE.test(value), { message: () => "must be subaccount_ plus an alphanumeric id" }));
|
|
7631
|
+
const WeiAmountSchema = Schema.String.pipe(Schema.filter((value) => WEI_AMOUNT_TELEMETRY_RE.test(value), { message: () => "must be a non-negative integer string" }));
|
|
7632
|
+
const CurrencyCodeSchema = Schema.String.pipe(Schema.filter((value) => value.length > 0, { message: () => "must be a non-empty currency code" }));
|
|
7633
|
+
const BalanceBucketSchema = Schema.Literal("zero", "nonzero");
|
|
7634
|
+
const TransferDirectionSchema = Schema.Literal("add", "out", "between");
|
|
7635
|
+
const SubAccountOpSchema = Schema.Literal("create", "rename", "delete");
|
|
7636
|
+
const OptionalAccountId = Schema.optional(AccountIdSchema);
|
|
7637
|
+
const OptionalSubAccountId = Schema.optional(SubAccountIdSchema);
|
|
7638
|
+
const OptionalWeiAmount = Schema.optional(WeiAmountSchema);
|
|
7639
|
+
const OptionalCurrencyCode = Schema.optional(CurrencyCodeSchema);
|
|
7640
|
+
const OptionalBalanceBucket = Schema.optional(BalanceBucketSchema);
|
|
7641
|
+
const OptionalTransferDirection = Schema.optional(TransferDirectionSchema);
|
|
7642
|
+
const OptionalSubAccountOp = Schema.optional(SubAccountOpSchema);
|
|
7643
|
+
const OptionalTrue = Schema.optional(Schema.Literal(true));
|
|
7644
|
+
const OptionalAddress = Schema.optional(AddressSchema);
|
|
7645
|
+
const OptionalAppId = Schema.optional(AppIdSchema);
|
|
7646
|
+
const OptionalBlockNumber = Schema.optional(BlockNumberSchema);
|
|
7647
|
+
const OptionalChainId = Schema.optional(ChainIdSchema);
|
|
7648
|
+
const OptionalDurationMs = Schema.optional(DurationMsSchema);
|
|
7649
|
+
const OptionalEpochMs = Schema.optional(EpochMsSchema);
|
|
7650
|
+
const OptionalPublishableKeyId = Schema.optional(PublishableKeyIdSchema);
|
|
7651
|
+
const OptionalTxHash = Schema.optional(TxHashSchema);
|
|
7652
|
+
const PAYMENT_ID_TELEMETRY_RE = /^payment_[0-9A-Za-z]+$/;
|
|
7653
|
+
const PAYEE_ID_TELEMETRY_RE = /^payee_[0-9A-Za-z]+$/;
|
|
7654
|
+
const PaymentIdTelemetrySchema = Schema.String.pipe(Schema.filter((value) => PAYMENT_ID_TELEMETRY_RE.test(value), { message: () => "must be payment_ plus an alphanumeric id" }));
|
|
7655
|
+
const PayeeIdTelemetrySchema = Schema.String.pipe(Schema.filter((value) => PAYEE_ID_TELEMETRY_RE.test(value), { message: () => "must be payee_ plus an alphanumeric id" }));
|
|
7656
|
+
const DocumentHashSchema = Schema.String.pipe(Schema.filter((value) => BYTES32_RE$2.test(value), { message: () => "must be 0x + 64 hex chars" }));
|
|
7657
|
+
const TelemetryEnvelopeProps = {
|
|
7658
|
+
capxul_e2e_run_id: OptionalString,
|
|
7659
|
+
correlationId: OptionalString,
|
|
7660
|
+
capxulEnv: OptionalString,
|
|
7661
|
+
sdkVersion: OptionalString,
|
|
7662
|
+
producer: OptionalString
|
|
7663
|
+
};
|
|
7664
|
+
const AuthOtpRequestedProps = Schema.Struct({
|
|
7665
|
+
...TelemetryEnvelopeProps,
|
|
7666
|
+
email: Schema.optional(PII),
|
|
7667
|
+
email_domain: OptionalString
|
|
7668
|
+
});
|
|
7669
|
+
const AuthOtpDeliveredProps = Schema.Struct({
|
|
7670
|
+
...TelemetryEnvelopeProps,
|
|
7671
|
+
durationMs: OptionalDurationMs,
|
|
7672
|
+
email: Schema.optional(PII),
|
|
7673
|
+
email_domain: OptionalString,
|
|
7674
|
+
resendMessageId: OptionalString
|
|
7675
|
+
});
|
|
7676
|
+
const AuthOtpExpiredProps = Schema.Struct({
|
|
7677
|
+
...TelemetryEnvelopeProps,
|
|
7678
|
+
email: Schema.optional(PII),
|
|
7679
|
+
email_domain: OptionalString
|
|
7680
|
+
});
|
|
7681
|
+
const AuthVerifiedProps = Schema.Struct({
|
|
7682
|
+
...TelemetryEnvelopeProps,
|
|
7683
|
+
auth_type: OptionalString
|
|
7684
|
+
});
|
|
7685
|
+
const AuthFailedProps = Schema.Struct({
|
|
7686
|
+
...TelemetryEnvelopeProps,
|
|
7687
|
+
email: Schema.optional(PII),
|
|
7688
|
+
auth_type: OptionalString,
|
|
7689
|
+
reason: OptionalString
|
|
7690
|
+
});
|
|
7691
|
+
const AuthSignedOutProps = Schema.Struct(TelemetryEnvelopeProps);
|
|
7692
|
+
const ProvisioningSafeCreatedProps = Schema.Struct({
|
|
7693
|
+
...TelemetryEnvelopeProps,
|
|
7694
|
+
safe_address: OptionalAddress
|
|
7695
|
+
});
|
|
7696
|
+
const ProvisioningSafeConfirmedProps = Schema.Struct({
|
|
7697
|
+
...TelemetryEnvelopeProps,
|
|
7698
|
+
chainId: OptionalChainId,
|
|
7699
|
+
deployedAt: OptionalEpochMs,
|
|
7700
|
+
deployedAtBlock: OptionalBlockNumber,
|
|
7701
|
+
deployTxHash: OptionalTxHash,
|
|
7702
|
+
durationMs: OptionalDurationMs,
|
|
7703
|
+
safe_address: OptionalAddress,
|
|
7704
|
+
userOpHash: OptionalTxHash
|
|
7705
|
+
});
|
|
7122
7706
|
const BootstrapResolvedProps = Schema.Struct({
|
|
7123
7707
|
...TelemetryEnvelopeProps,
|
|
7124
7708
|
applicationId: OptionalAppId,
|
|
@@ -7184,6 +7768,10 @@ const TransferRequestedProps = Schema.Struct({
|
|
|
7184
7768
|
amount: OptionalWeiAmount,
|
|
7185
7769
|
direction: OptionalTransferDirection
|
|
7186
7770
|
});
|
|
7771
|
+
const TransferBackendReceivedProps = Schema.Struct({
|
|
7772
|
+
...TelemetryEnvelopeProps,
|
|
7773
|
+
direction: OptionalTransferDirection
|
|
7774
|
+
});
|
|
7187
7775
|
const TransferConfirmedProps = Schema.Struct({
|
|
7188
7776
|
...TelemetryEnvelopeProps,
|
|
7189
7777
|
amount: OptionalWeiAmount,
|
|
@@ -7400,6 +7988,10 @@ Schema.Struct({
|
|
|
7400
7988
|
name: Schema.Literal("transfer_requested"),
|
|
7401
7989
|
props: Schema.optional(TransferRequestedProps)
|
|
7402
7990
|
});
|
|
7991
|
+
Schema.Struct({
|
|
7992
|
+
name: Schema.Literal("transfer_backend_received"),
|
|
7993
|
+
props: Schema.optional(TransferBackendReceivedProps)
|
|
7994
|
+
});
|
|
7403
7995
|
Schema.Struct({
|
|
7404
7996
|
name: Schema.Literal("transfer_confirmed"),
|
|
7405
7997
|
props: Schema.optional(TransferConfirmedProps)
|
|
@@ -10503,6 +11095,76 @@ function listOrgsProgram() {
|
|
|
10503
11095
|
});
|
|
10504
11096
|
}
|
|
10505
11097
|
//#endregion
|
|
11098
|
+
//#region ../../packages/sdk/src/client/org-lifecycle.ts
|
|
11099
|
+
function fail$1(error) {
|
|
11100
|
+
return {
|
|
11101
|
+
ok: false,
|
|
11102
|
+
error
|
|
11103
|
+
};
|
|
11104
|
+
}
|
|
11105
|
+
function validateOrganizationLifecycleScope(orgId, lifecycle) {
|
|
11106
|
+
if (String(lifecycle.orgId) !== String(orgId)) return fail$1(Errors.invalidInput("orgId", "Organization lifecycle scope does not match"));
|
|
11107
|
+
return {
|
|
11108
|
+
ok: true,
|
|
11109
|
+
value: lifecycle
|
|
11110
|
+
};
|
|
11111
|
+
}
|
|
11112
|
+
/** Advance only the steps still required by one durable Organization lane. */
|
|
11113
|
+
async function advanceOrganizationSetup(setup, orgId, initial, signal) {
|
|
11114
|
+
const scopedInitial = validateOrganizationLifecycleScope(orgId, initial);
|
|
11115
|
+
if (!scopedInitial.ok) return scopedInitial;
|
|
11116
|
+
let lifecycle = scopedInitial.value;
|
|
11117
|
+
for (let transition = 0; transition < 3; transition += 1) {
|
|
11118
|
+
if (lifecycle.status !== "settingUp") return {
|
|
11119
|
+
ok: true,
|
|
11120
|
+
value: lifecycle
|
|
11121
|
+
};
|
|
11122
|
+
const currentStep = lifecycle.step;
|
|
11123
|
+
if (signal?.aborted) {
|
|
11124
|
+
const cancelled = Errors.cancelled({ operation: "organization.setup" });
|
|
11125
|
+
return recordRetryableCancellation(setup, orgId, lifecycle.step, cancelled);
|
|
11126
|
+
}
|
|
11127
|
+
const stepInput = {
|
|
11128
|
+
orgId,
|
|
11129
|
+
...signal === void 0 ? {} : { signal }
|
|
11130
|
+
};
|
|
11131
|
+
const next = lifecycle.step === "preparingFounderAccount" ? await setup.prepareFounderAccount(stepInput) : lifecycle.step === "awaitingFounderAuthorization" || lifecycle.step === "submittingBootstrap" ? await setup.authorizeAndSubmitBootstrap(stepInput) : await setup.confirmSubmittedBootstrap(stepInput);
|
|
11132
|
+
if (!next.ok) return next.error.code === "CANCELLED" ? recordRetryableCancellation(setup, orgId, lifecycle.step, next.error) : next;
|
|
11133
|
+
const scopedNext = validateOrganizationLifecycleScope(orgId, next.value);
|
|
11134
|
+
if (!scopedNext.ok) return scopedNext;
|
|
11135
|
+
lifecycle = scopedNext.value;
|
|
11136
|
+
if (currentStep === "confirmingBootstrap") return {
|
|
11137
|
+
ok: true,
|
|
11138
|
+
value: lifecycle
|
|
11139
|
+
};
|
|
11140
|
+
}
|
|
11141
|
+
if (lifecycle.status !== "settingUp" || lifecycle.step === "confirmingBootstrap") return {
|
|
11142
|
+
ok: true,
|
|
11143
|
+
value: lifecycle
|
|
11144
|
+
};
|
|
11145
|
+
return fail$1(Errors.wrongState({
|
|
11146
|
+
method: "organization.setup",
|
|
11147
|
+
currentState: lifecycle.step,
|
|
11148
|
+
validStates: [
|
|
11149
|
+
"confirmingBootstrap",
|
|
11150
|
+
"ready",
|
|
11151
|
+
"failed"
|
|
11152
|
+
]
|
|
11153
|
+
}));
|
|
11154
|
+
}
|
|
11155
|
+
async function recordRetryableCancellation(setup, orgId, at, cancelled) {
|
|
11156
|
+
const recorded = await setup.recordFailure({
|
|
11157
|
+
orgId,
|
|
11158
|
+
at,
|
|
11159
|
+
error: cancelled,
|
|
11160
|
+
retryable: true
|
|
11161
|
+
});
|
|
11162
|
+
if (!recorded.ok) return recorded;
|
|
11163
|
+
const scopedRecorded = validateOrganizationLifecycleScope(orgId, recorded.value);
|
|
11164
|
+
if (!scopedRecorded.ok) return scopedRecorded;
|
|
11165
|
+
return fail$1(cancelled);
|
|
11166
|
+
}
|
|
11167
|
+
//#endregion
|
|
10506
11168
|
//#region ../../packages/sdk/src/client/org.ts
|
|
10507
11169
|
/**
|
|
10508
11170
|
* Org method surface (canon §C2/§C3, D13). S1 (#274) wires `createOrg` /
|
|
@@ -10551,6 +11213,36 @@ function makeOrgMethods(deps) {
|
|
|
10551
11213
|
},
|
|
10552
11214
|
...convexCall === void 0 ? {} : { convexCall }
|
|
10553
11215
|
}),
|
|
11216
|
+
async getLifecycle(options) {
|
|
11217
|
+
if (options?.signal?.aborted) return {
|
|
11218
|
+
ok: false,
|
|
11219
|
+
error: Errors.cancelled({ operation: "org.getLifecycle" })
|
|
11220
|
+
};
|
|
11221
|
+
if (deps.organizationSetup === void 0) return {
|
|
11222
|
+
ok: false,
|
|
11223
|
+
error: Errors.notImplemented("organizationSetup", "getLifecycle")
|
|
11224
|
+
};
|
|
11225
|
+
const loaded = await deps.organizationSetup.loadLifecycle({ orgId });
|
|
11226
|
+
if (!loaded.ok) return loaded;
|
|
11227
|
+
return validateOrganizationLifecycleScope(orgId, loaded.value);
|
|
11228
|
+
},
|
|
11229
|
+
async retrySetup(options) {
|
|
11230
|
+
if (options?.signal?.aborted) return {
|
|
11231
|
+
ok: false,
|
|
11232
|
+
error: Errors.cancelled({ operation: "org.retrySetup" })
|
|
11233
|
+
};
|
|
11234
|
+
const setup = deps.organizationSetup;
|
|
11235
|
+
if (setup === void 0) return {
|
|
11236
|
+
ok: false,
|
|
11237
|
+
error: Errors.notImplemented("organizationSetup", "retrySetup")
|
|
11238
|
+
};
|
|
11239
|
+
const retried = await setup.retry({
|
|
11240
|
+
orgId,
|
|
11241
|
+
...options?.signal === void 0 ? {} : { signal: options.signal }
|
|
11242
|
+
});
|
|
11243
|
+
if (!retried.ok) return retried;
|
|
11244
|
+
return advanceOrganizationSetup(setup, orgId, retried.value, options?.signal);
|
|
11245
|
+
},
|
|
10554
11246
|
profile: {
|
|
10555
11247
|
get(_options) {
|
|
10556
11248
|
if (_options?.signal?.aborted) return Promise.resolve({
|
|
@@ -10584,12 +11276,12 @@ function makeOrgMethods(deps) {
|
|
|
10584
11276
|
ok: false,
|
|
10585
11277
|
error: treasury.error
|
|
10586
11278
|
};
|
|
10587
|
-
const
|
|
10588
|
-
if (!
|
|
11279
|
+
const orgList = await toCapxulResult(listOrgsProgram(), layer);
|
|
11280
|
+
if (!orgList.ok) return {
|
|
10589
11281
|
ok: false,
|
|
10590
|
-
error:
|
|
11282
|
+
error: orgList.error
|
|
10591
11283
|
};
|
|
10592
|
-
const org =
|
|
11284
|
+
const org = orgList.value.find((candidate) => candidate.id === orgId);
|
|
10593
11285
|
return {
|
|
10594
11286
|
ok: true,
|
|
10595
11287
|
value: {
|
|
@@ -10777,7 +11469,6 @@ function normalizePaymentTiming(payment) {
|
|
|
10777
11469
|
}
|
|
10778
11470
|
//#endregion
|
|
10779
11471
|
//#region ../../packages/sdk/src/flows/onboarding.ts
|
|
10780
|
-
const DEFAULT_ORG_TEMPLATE = "Startup";
|
|
10781
11472
|
async function runCompletePersonalOnboarding(ops, input) {
|
|
10782
11473
|
const validated = validatePersonalInput(input);
|
|
10783
11474
|
if (!validated.ok) return validated;
|
|
@@ -10801,11 +11492,13 @@ async function runCompletePersonalOnboarding(ops, input) {
|
|
|
10801
11492
|
value: { lifecycle: lifecycle.value }
|
|
10802
11493
|
};
|
|
10803
11494
|
}
|
|
10804
|
-
async function runCompleteOrganizationOnboarding(ops, input) {
|
|
11495
|
+
async function runCompleteOrganizationOnboarding(ops, input, options) {
|
|
10805
11496
|
const validated = validateOrganizationInput(input);
|
|
10806
11497
|
if (!validated.ok) return validated;
|
|
10807
11498
|
const session = await ops.currentSession();
|
|
10808
11499
|
if (session === null) return fail(Errors.notAuthenticated());
|
|
11500
|
+
const setup = ops.organizationSetup;
|
|
11501
|
+
if (setup === void 0) return fail(Errors.notImplemented("organizationSetup", "completeOrganization"));
|
|
10809
11502
|
const written = await ops.completeIdentityOnboarding({
|
|
10810
11503
|
authUserId: session.authUserId,
|
|
10811
11504
|
email: session.email,
|
|
@@ -10813,22 +11506,18 @@ async function runCompleteOrganizationOnboarding(ops, input) {
|
|
|
10813
11506
|
country: validated.value.country
|
|
10814
11507
|
});
|
|
10815
11508
|
if (!written.ok) return fail(written.error);
|
|
10816
|
-
const
|
|
10817
|
-
if (!provisioned.ok) return fail(provisioned.error);
|
|
10818
|
-
const org = await ops.createOrg({
|
|
11509
|
+
const started = await setup.startOrResume({
|
|
10819
11510
|
name: validated.value.organizationName,
|
|
10820
11511
|
handle: validated.value.handle,
|
|
10821
|
-
template: DEFAULT_ORG_TEMPLATE,
|
|
10822
11512
|
country: validated.value.country
|
|
10823
11513
|
});
|
|
10824
|
-
if (!
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
if (!lifecycle.ok) return fail(lifecycle.error);
|
|
11514
|
+
if (!started.ok) return fail(started.error);
|
|
11515
|
+
const lifecycle = await advanceOrganizationSetup(setup, started.value.orgId, started.value.lifecycle, options?.signal);
|
|
11516
|
+
if (!lifecycle.ok) return lifecycle;
|
|
10828
11517
|
return {
|
|
10829
11518
|
ok: true,
|
|
10830
11519
|
value: {
|
|
10831
|
-
|
|
11520
|
+
orgId: started.value.orgId,
|
|
10832
11521
|
lifecycle: lifecycle.value
|
|
10833
11522
|
}
|
|
10834
11523
|
};
|
|
@@ -10919,8 +11608,7 @@ function fail(error) {
|
|
|
10919
11608
|
* Onboarding method surface. The thin namespace over the `flows/onboarding.ts`
|
|
10920
11609
|
* choreography: it adds the `signal`-abort pre-check and delegates to the run
|
|
10921
11610
|
* functions. The `OnboardingOps` seam is supplied by `assembleCapxulClient`
|
|
10922
|
-
* (real ops
|
|
10923
|
-
* (in-memory double).
|
|
11611
|
+
* (real identity/Account ops plus Organization setup capability) or by tests.
|
|
10924
11612
|
*/
|
|
10925
11613
|
function makeOnboardingMethods(ops) {
|
|
10926
11614
|
return {
|
|
@@ -10936,7 +11624,7 @@ function makeOnboardingMethods(ops) {
|
|
|
10936
11624
|
ok: false,
|
|
10937
11625
|
error: Errors.cancelled({ operation: "onboarding.completeOrganization" })
|
|
10938
11626
|
});
|
|
10939
|
-
return runCompleteOrganizationOnboarding(ops, input);
|
|
11627
|
+
return runCompleteOrganizationOnboarding(ops, input, options);
|
|
10940
11628
|
}
|
|
10941
11629
|
};
|
|
10942
11630
|
}
|
|
@@ -11123,7 +11811,8 @@ function assembleCapxulClient(input) {
|
|
|
11123
11811
|
...selectedOrgPort === void 0 ? {} : { orgPort: selectedOrgPort },
|
|
11124
11812
|
...input.orgRolesDeploymentPort === void 0 ? {} : { orgRolesDeploymentPort: input.orgRolesDeploymentPort },
|
|
11125
11813
|
...input.orgSpendPort === void 0 ? {} : { orgSpendPort: input.orgSpendPort },
|
|
11126
|
-
convexCall: input.ports.convexCall
|
|
11814
|
+
convexCall: input.ports.convexCall,
|
|
11815
|
+
...input.organizationSetup === void 0 ? {} : { organizationSetup: input.organizationSetup }
|
|
11127
11816
|
});
|
|
11128
11817
|
if (selectedOrgPort !== void 0) detectPendingOrgInvitations = async () => {
|
|
11129
11818
|
await orgMethods.orgs.detectAndAcceptPendingInvitations();
|
|
@@ -11146,7 +11835,7 @@ function assembleCapxulClient(input) {
|
|
|
11146
11835
|
triggerProvisioning: () => account._internal.provision(),
|
|
11147
11836
|
kickProvisioning: () => kickProvisioning?.(),
|
|
11148
11837
|
readLifecycle: () => account.getLifecycle(),
|
|
11149
|
-
|
|
11838
|
+
...input.organizationSetup === void 0 ? {} : { organizationSetup: input.organizationSetup }
|
|
11150
11839
|
});
|
|
11151
11840
|
return {
|
|
11152
11841
|
auth,
|
|
@@ -11186,6 +11875,34 @@ function assembleCapxulClient(input) {
|
|
|
11186
11875
|
//#endregion
|
|
11187
11876
|
//#region ../../packages/sdk/src/observation.ts
|
|
11188
11877
|
const SDK_VERSION$1 = version;
|
|
11878
|
+
/**
|
|
11879
|
+
* Fan one SDK failure out to several adapters (issue #877). The SDK's own
|
|
11880
|
+
* first-party relay and an optional host-provided adapter both observe the same
|
|
11881
|
+
* failure. Order matters for `resolveContext`: the FIRST adapter that returns a
|
|
11882
|
+
* context wins, so pass the host adapter first to keep its call-start snapshot.
|
|
11883
|
+
* Each capture is isolated — a throwing adapter never blocks its peers or the
|
|
11884
|
+
* SDK. Returns `undefined` when no adapters are present (zero observation work).
|
|
11885
|
+
*/
|
|
11886
|
+
function composeObservationAdapters(...adapters) {
|
|
11887
|
+
const present = adapters.filter((adapter) => adapter !== void 0);
|
|
11888
|
+
if (present.length === 0) return void 0;
|
|
11889
|
+
if (present.length === 1) return present[0];
|
|
11890
|
+
const fanOut = (select) => {
|
|
11891
|
+
for (const adapter of present) try {
|
|
11892
|
+
ignoreDeliveryFailure(select(adapter));
|
|
11893
|
+
} catch {}
|
|
11894
|
+
};
|
|
11895
|
+
return {
|
|
11896
|
+
resolveContext: () => {
|
|
11897
|
+
for (const adapter of present) try {
|
|
11898
|
+
const context = adapter.resolveContext?.();
|
|
11899
|
+
if (context !== void 0) return context;
|
|
11900
|
+
} catch {}
|
|
11901
|
+
},
|
|
11902
|
+
captureOperationFailure: (failure) => fanOut((adapter) => adapter.captureOperationFailure(failure)),
|
|
11903
|
+
captureException: (failure) => fanOut((adapter) => adapter.captureException(failure))
|
|
11904
|
+
};
|
|
11905
|
+
}
|
|
11189
11906
|
/** @internal Decorates public client method bundles at the owning SDK boundary. */
|
|
11190
11907
|
function observeSdkClient(client, adapter) {
|
|
11191
11908
|
if (adapter === void 0) return client;
|
|
@@ -11224,18 +11941,20 @@ function observeSdkClient(client, adapter) {
|
|
|
11224
11941
|
if (cached !== void 0) return cached;
|
|
11225
11942
|
const wrapped = new Proxy(callable, {
|
|
11226
11943
|
apply(currentTarget, _thisArg, args) {
|
|
11944
|
+
const invocationContext = resolveAdapterContext(adapter);
|
|
11945
|
+
const invocationArgs = carryInvocationContext(operation, args, invocationContext);
|
|
11227
11946
|
let output;
|
|
11228
11947
|
try {
|
|
11229
|
-
output = Reflect.apply(currentTarget, owner,
|
|
11948
|
+
output = Reflect.apply(currentTarget, owner, invocationArgs);
|
|
11230
11949
|
} catch (cause) {
|
|
11231
|
-
report(adapter, "exception", operation, cause);
|
|
11950
|
+
report(adapter, "exception", operation, cause, invocationContext);
|
|
11232
11951
|
throw cause;
|
|
11233
11952
|
}
|
|
11234
|
-
if (isPromiseLike(output)) return Promise.resolve(output).then((result) => processOutput(result, path), (cause) => {
|
|
11235
|
-
report(adapter, "exception", operation, cause);
|
|
11953
|
+
if (isPromiseLike(output)) return Promise.resolve(output).then((result) => processOutput(result, path, invocationContext), (cause) => {
|
|
11954
|
+
report(adapter, "exception", operation, cause, invocationContext);
|
|
11236
11955
|
throw cause;
|
|
11237
11956
|
});
|
|
11238
|
-
return processOutput(output, path);
|
|
11957
|
+
return processOutput(output, path, invocationContext);
|
|
11239
11958
|
},
|
|
11240
11959
|
get(currentTarget, property) {
|
|
11241
11960
|
const attached = Reflect.get(currentTarget, property, currentTarget);
|
|
@@ -11248,9 +11967,9 @@ function observeSdkClient(client, adapter) {
|
|
|
11248
11967
|
}
|
|
11249
11968
|
return isPlainObject(value) ? wrapObject(value, path) : value;
|
|
11250
11969
|
};
|
|
11251
|
-
const processOutput = (output, path) => {
|
|
11970
|
+
const processOutput = (output, path, invocationContext) => {
|
|
11252
11971
|
if (isFailedResult(output)) {
|
|
11253
|
-
report(adapter, "operation", path.join("."), output.error);
|
|
11972
|
+
report(adapter, "operation", path.join("."), output.error, invocationContext);
|
|
11254
11973
|
return output;
|
|
11255
11974
|
}
|
|
11256
11975
|
if (isCapxulResult(output)) return output;
|
|
@@ -11258,24 +11977,40 @@ function observeSdkClient(client, adapter) {
|
|
|
11258
11977
|
};
|
|
11259
11978
|
return wrapObject(client, []);
|
|
11260
11979
|
}
|
|
11980
|
+
function carryInvocationContext(operation, args, context) {
|
|
11981
|
+
if (operation !== "subAccounts.transfer" || !isPlainObject(args[0])) return args;
|
|
11982
|
+
return [attachInvocationObservation({ ...args[0] }, context), ...args.slice(1)];
|
|
11983
|
+
}
|
|
11261
11984
|
/** @internal Reports a factory-level typed failure without changing its identity. */
|
|
11262
11985
|
function observeFailedResult(result, adapter, operation) {
|
|
11263
|
-
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error);
|
|
11986
|
+
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterContext(adapter));
|
|
11264
11987
|
return result;
|
|
11265
11988
|
}
|
|
11266
|
-
function report(adapter, kind, operation, cause) {
|
|
11989
|
+
function report(adapter, kind, operation, cause, invocationContext) {
|
|
11267
11990
|
const operationName = normalizeOperation(operation);
|
|
11268
11991
|
const kindName = normalizeErrorKind(errorKind(cause));
|
|
11269
|
-
const
|
|
11992
|
+
const context = sanitizeObservationContext({
|
|
11993
|
+
...invocationContext,
|
|
11994
|
+
...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
|
|
11995
|
+
});
|
|
11996
|
+
const failure = markFailureInvocationSnapshot({
|
|
11270
11997
|
exception: syntheticException(operationName, kindName),
|
|
11271
11998
|
sdkVersion: SDK_VERSION$1,
|
|
11272
11999
|
operation: operationName,
|
|
11273
|
-
errorKind: kindName
|
|
11274
|
-
|
|
12000
|
+
errorKind: kindName,
|
|
12001
|
+
...context === void 0 ? {} : { context }
|
|
12002
|
+
});
|
|
11275
12003
|
try {
|
|
11276
12004
|
ignoreDeliveryFailure(kind === "operation" ? adapter.captureOperationFailure(failure) : adapter.captureException(failure));
|
|
11277
12005
|
} catch {}
|
|
11278
12006
|
}
|
|
12007
|
+
function resolveAdapterContext(adapter) {
|
|
12008
|
+
try {
|
|
12009
|
+
return adapter.resolveContext?.();
|
|
12010
|
+
} catch {
|
|
12011
|
+
return;
|
|
12012
|
+
}
|
|
12013
|
+
}
|
|
11279
12014
|
function ignoreDeliveryFailure(delivery) {
|
|
11280
12015
|
if (!isPromiseLike(delivery)) return;
|
|
11281
12016
|
try {
|
|
@@ -11317,6 +12052,43 @@ function isCapxulResult(value) {
|
|
|
11317
12052
|
function isFailedResult(value) {
|
|
11318
12053
|
return isCapxulResult(value) && value.ok === false && "error" in value;
|
|
11319
12054
|
}
|
|
12055
|
+
//#endregion
|
|
12056
|
+
//#region ../../packages/sdk/src/observation-relay.ts
|
|
12057
|
+
/**
|
|
12058
|
+
* Build the SDK-owned first-party relay adapter. Both capture entry points send
|
|
12059
|
+
* the same redacted envelope fire-and-forget; delivery is fully isolated from
|
|
12060
|
+
* the SDK's `CapxulResult` and can never throw into the caller.
|
|
12061
|
+
*/
|
|
12062
|
+
function createCapxulFirstPartyRelay(options) {
|
|
12063
|
+
const fetchImpl = options.fetch ?? resolveGlobalFetch();
|
|
12064
|
+
const send = (failure) => {
|
|
12065
|
+
if (fetchImpl === void 0) return;
|
|
12066
|
+
try {
|
|
12067
|
+
const headers = { "content-type": "application/json" };
|
|
12068
|
+
const encodedContext = encodeObservationContextHeader(failure.context);
|
|
12069
|
+
if (encodedContext !== void 0) headers[OBSERVATION_CONTEXT_HEADER] = encodedContext;
|
|
12070
|
+
const body = JSON.stringify({
|
|
12071
|
+
operation: failure.operation,
|
|
12072
|
+
error_kind: failure.errorKind,
|
|
12073
|
+
sdk_version: failure.sdkVersion
|
|
12074
|
+
});
|
|
12075
|
+
Promise.resolve(fetchImpl(options.ingestUrl, {
|
|
12076
|
+
method: "POST",
|
|
12077
|
+
headers,
|
|
12078
|
+
body,
|
|
12079
|
+
keepalive: true
|
|
12080
|
+
})).catch(() => void 0);
|
|
12081
|
+
} catch {}
|
|
12082
|
+
};
|
|
12083
|
+
return {
|
|
12084
|
+
captureOperationFailure: send,
|
|
12085
|
+
captureException: send
|
|
12086
|
+
};
|
|
12087
|
+
}
|
|
12088
|
+
function resolveGlobalFetch() {
|
|
12089
|
+
const candidate = globalThis.fetch;
|
|
12090
|
+
return typeof candidate === "function" ? candidate : void 0;
|
|
12091
|
+
}
|
|
11320
12092
|
const SDK_VERSION = version;
|
|
11321
12093
|
const collectProductionFlowPorts = Effect.gen(function* () {
|
|
11322
12094
|
const authClient = yield* AuthClientPortTag;
|
|
@@ -11424,11 +12196,13 @@ function productionBootstrapPortLayer(bootstrap) {
|
|
|
11424
12196
|
function productionAuthClientLayer(input, refreshConvexAuthRef) {
|
|
11425
12197
|
return (input.runtime === "browser" ? BetterAuthBrowserLayer({
|
|
11426
12198
|
authBaseUrl: input.runtimeUrls.authBaseUrl,
|
|
11427
|
-
...input.fetch === void 0 ? {} : { fetch: input.fetch }
|
|
12199
|
+
...input.fetch === void 0 ? {} : { fetch: input.fetch },
|
|
12200
|
+
...input.observation === void 0 ? {} : { observation: input.observation }
|
|
11428
12201
|
}) : BetterAuthNodeLayer({
|
|
11429
12202
|
authBaseUrl: input.runtimeUrls.authBaseUrl,
|
|
11430
12203
|
...input.origin === void 0 ? {} : { origin: input.origin },
|
|
11431
|
-
...input.fetch === void 0 ? {} : { fetch: input.fetch }
|
|
12204
|
+
...input.fetch === void 0 ? {} : { fetch: input.fetch },
|
|
12205
|
+
...input.observation === void 0 ? {} : { observation: input.observation }
|
|
11432
12206
|
})).pipe(Layer.map((context) => {
|
|
11433
12207
|
const authClient = Context.get(context, AuthClientPortTag);
|
|
11434
12208
|
return Context.make(AuthClientPortTag, refreshConvexAuthOnSession(authClient, () => {
|
|
@@ -11447,6 +12221,8 @@ function productionAuthCacheLayer(input) {
|
|
|
11447
12221
|
function productionConvexCallLayer(input, refreshConvexAuthRef) {
|
|
11448
12222
|
return Layer.unwrapEffect(Effect.map(AuthClientPortTag, (authClient) => ConvexCallLayer({
|
|
11449
12223
|
convexUrl: input.runtimeUrls.convexUrl,
|
|
12224
|
+
...input.applicationId === void 0 ? {} : { applicationId: input.applicationId },
|
|
12225
|
+
...input.observation === void 0 ? {} : { observation: input.observation },
|
|
11450
12226
|
...input.convexClient === void 0 ? {} : { client: input.convexClient },
|
|
11451
12227
|
tokenProvider: async ({ forceRefreshToken }) => {
|
|
11452
12228
|
const tokenResult = await Effect.runPromise(Effect.either(authClient.getConvexJwt({
|
|
@@ -11478,7 +12254,8 @@ async function createProductionAdapters(input) {
|
|
|
11478
12254
|
const closeScope = idempotentClose(() => Effect.runPromise(Scope.close(scope, Exit.void)));
|
|
11479
12255
|
const bootstrapLayer = HttpBootstrapLayer({
|
|
11480
12256
|
bootstrapBaseUrl: resolvedInput.value.bootstrapBaseUrl,
|
|
11481
|
-
...input.fetch === void 0 ? {} : { fetch: input.fetch }
|
|
12257
|
+
...input.fetch === void 0 ? {} : { fetch: input.fetch },
|
|
12258
|
+
...input.observation === void 0 ? {} : { observation: input.observation }
|
|
11482
12259
|
});
|
|
11483
12260
|
try {
|
|
11484
12261
|
const bootstrapContext = await Effect.runPromise(Layer.buildWithScope(bootstrapLayer, scope));
|
|
@@ -11536,6 +12313,8 @@ async function createProductionAdapters(input) {
|
|
|
11536
12313
|
...resolvedInput.value.origin === void 0 ? {} : { origin: resolvedInput.value.origin },
|
|
11537
12314
|
runtimeUrls: runtimeUrls.value,
|
|
11538
12315
|
chainId: bootstrapResult.value.chainId,
|
|
12316
|
+
applicationId: bootstrapResult.value.applicationId,
|
|
12317
|
+
...input.observation === void 0 ? {} : { observation: input.observation },
|
|
11539
12318
|
...input.authCache === void 0 ? {} : { authCache: input.authCache },
|
|
11540
12319
|
...input.telemetry === void 0 ? {} : { telemetry: input.telemetry },
|
|
11541
12320
|
...injectedClient === void 0 ? {} : { convexClient: injectedClient },
|
|
@@ -11597,7 +12376,7 @@ async function createCapxulClient(input) {
|
|
|
11597
12376
|
...input.authBaseUrl === void 0 ? {} : { override: input.authBaseUrl }
|
|
11598
12377
|
});
|
|
11599
12378
|
let signer = input.signer;
|
|
11600
|
-
if (signer === void 0 &&
|
|
12379
|
+
if (signer === void 0 && runtime === "browser") signer = createOpenfortBrowserSignerFromBootstrap({
|
|
11601
12380
|
...adapters.value.bootstrap,
|
|
11602
12381
|
authBaseUrl: resolvedAuthBaseUrl
|
|
11603
12382
|
});
|
|
@@ -11607,23 +12386,33 @@ async function createCapxulClient(input) {
|
|
|
11607
12386
|
authCache: adapters.value.ports.authCache,
|
|
11608
12387
|
requirement: input.requirement ?? "none",
|
|
11609
12388
|
...signer === void 0 ? {} : { signer },
|
|
12389
|
+
orgPort: new ConvexOrganizationAdapter({ convex: adapters.value.ports.convexCall }),
|
|
12390
|
+
...signer === void 0 ? {} : { organizationSetup: new ConvexOrganizationSetupAdapter({
|
|
12391
|
+
convex: adapters.value.ports.convexCall,
|
|
12392
|
+
signer
|
|
12393
|
+
}) },
|
|
11610
12394
|
...input.signal === void 0 ? {} : { signal: input.signal },
|
|
11611
12395
|
...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs },
|
|
11612
12396
|
invokeTimeoutMs: input.invokeTimeoutMs ?? 3e4
|
|
11613
12397
|
}), signer);
|
|
11614
12398
|
const upstreamClose = adapters.value.close;
|
|
12399
|
+
const value = {
|
|
12400
|
+
...client,
|
|
12401
|
+
_internal: {
|
|
12402
|
+
...client._internal,
|
|
12403
|
+
close: async () => {
|
|
12404
|
+
if ("resetSession" in (signer ?? {})) signer.resetSession();
|
|
12405
|
+
await upstreamClose();
|
|
12406
|
+
}
|
|
12407
|
+
}
|
|
12408
|
+
};
|
|
12409
|
+
const relay = runtime === "browser" ? createCapxulFirstPartyRelay({
|
|
12410
|
+
ingestUrl: deriveObserveIngestUrl(adapters.value.bootstrap),
|
|
12411
|
+
...input.fetch === void 0 ? {} : { fetch: input.fetch }
|
|
12412
|
+
}) : void 0;
|
|
11615
12413
|
return {
|
|
11616
12414
|
ok: true,
|
|
11617
|
-
value: observeSdkClient(
|
|
11618
|
-
...client,
|
|
11619
|
-
_internal: {
|
|
11620
|
-
...client._internal,
|
|
11621
|
-
close: async () => {
|
|
11622
|
-
if ("resetSession" in (signer ?? {})) signer.resetSession();
|
|
11623
|
-
await upstreamClose();
|
|
11624
|
-
}
|
|
11625
|
-
}
|
|
11626
|
-
}, input.observation)
|
|
12415
|
+
value: observeSdkClient(value, composeObservationAdapters(input.observation, relay))
|
|
11627
12416
|
};
|
|
11628
12417
|
} catch (cause) {
|
|
11629
12418
|
await adapters.value.close().catch(() => void 0);
|
|
@@ -11665,6 +12454,38 @@ function resolveInput(input) {
|
|
|
11665
12454
|
};
|
|
11666
12455
|
}
|
|
11667
12456
|
}
|
|
12457
|
+
/**
|
|
12458
|
+
* Address of the Capxul client-relay ingest endpoint (Pipe 1, issue #877). The
|
|
12459
|
+
* HTTP router that serves `/v1/client/observe` lives on the deployment's
|
|
12460
|
+
* `.convex.site` host, while the bootstrap-resolved `convexUrl` is the sibling
|
|
12461
|
+
* `.convex.cloud` (WebSocket/query) host — the same deterministic pairing
|
|
12462
|
+
* `mintQuickstartKey` inverts. For any standard Convex deployment (including
|
|
12463
|
+
* production) rewriting the suffix targets the router directly with no host
|
|
12464
|
+
* proxy, so it is the primary rule.
|
|
12465
|
+
*
|
|
12466
|
+
* `siteBaseUrl` is deliberately NOT the primary source: it is an app-configured
|
|
12467
|
+
* field that defaults to a placeholder (`https://capxul.local`, see
|
|
12468
|
+
* `credentials/applications.ts`) for registered applications, so trusting it
|
|
12469
|
+
* outright would POST to a dead host for the common case. It is only consulted
|
|
12470
|
+
* as a fallback for a custom-domain `convexUrl` (no deterministic `.convex.site`
|
|
12471
|
+
* sibling) when it carries a real, non-placeholder origin.
|
|
12472
|
+
*/
|
|
12473
|
+
function deriveObserveIngestUrl(bootstrap) {
|
|
12474
|
+
const convexUrl = bootstrap.convexUrl.replace(/\/+$/, "");
|
|
12475
|
+
if (convexUrl.endsWith(".convex.cloud")) return `${convexUrl.replace(/\.convex\.cloud$/, ".convex.site")}/v1/client/observe`;
|
|
12476
|
+
return `${(usableSiteOrigin(bootstrap.siteBaseUrl) ?? convexUrl).replace(/\/+$/, "")}/v1/client/observe`;
|
|
12477
|
+
}
|
|
12478
|
+
/** A configured `siteBaseUrl` usable as a router host, or `undefined` if it is the placeholder. */
|
|
12479
|
+
function usableSiteOrigin(siteBaseUrl) {
|
|
12480
|
+
try {
|
|
12481
|
+
const url = new URL(siteBaseUrl);
|
|
12482
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return void 0;
|
|
12483
|
+
if (url.hostname === "capxul.local") return void 0;
|
|
12484
|
+
return url.origin;
|
|
12485
|
+
} catch {
|
|
12486
|
+
return;
|
|
12487
|
+
}
|
|
12488
|
+
}
|
|
11668
12489
|
function detectRuntime() {
|
|
11669
12490
|
const globalAny = globalThis;
|
|
11670
12491
|
return globalAny.window !== void 0 || globalAny.document !== void 0 ? "browser" : "node";
|
|
@@ -12273,7 +13094,7 @@ async function signUserOperation(parameters) {
|
|
|
12273
13094
|
}
|
|
12274
13095
|
//#endregion
|
|
12275
13096
|
//#region ../../node_modules/.pnpm/permissionless@0.3.4_viem@2.53.1_typescript@5.9.2_zod@4.4.3_/node_modules/permissionless/_esm/accounts/safe/toSafeSmartAccount.js
|
|
12276
|
-
const multiSendAbi
|
|
13097
|
+
const multiSendAbi = [{
|
|
12277
13098
|
inputs: [{
|
|
12278
13099
|
internalType: "bytes",
|
|
12279
13100
|
name: "transactions",
|
|
@@ -12757,7 +13578,7 @@ const encodeInternalTransaction = (tx) => {
|
|
|
12757
13578
|
};
|
|
12758
13579
|
const encodeMultiSend = (txs) => {
|
|
12759
13580
|
return encodeFunctionData({
|
|
12760
|
-
abi: multiSendAbi
|
|
13581
|
+
abi: multiSendAbi,
|
|
12761
13582
|
functionName: "multiSend",
|
|
12762
13583
|
args: [`0x${txs.map((tx) => encodeInternalTransaction(tx)).join("")}`]
|
|
12763
13584
|
});
|
|
@@ -13282,7 +14103,7 @@ async function toSafeSmartAccount(parameters) {
|
|
|
13282
14103
|
const data = decoded.args[2];
|
|
13283
14104
|
if (to === multiSendCallOnlyAddress) {
|
|
13284
14105
|
const dataToDecode = decodeFunctionData({
|
|
13285
|
-
abi: multiSendAbi
|
|
14106
|
+
abi: multiSendAbi,
|
|
13286
14107
|
data
|
|
13287
14108
|
}).args[0];
|
|
13288
14109
|
const transactions = [];
|
|
@@ -13471,123 +14292,6 @@ async function toSafeSmartAccount(parameters) {
|
|
|
13471
14292
|
}
|
|
13472
14293
|
});
|
|
13473
14294
|
}
|
|
13474
|
-
//#endregion
|
|
13475
|
-
//#region ../../packages/sdk/src/ports/org.ts
|
|
13476
|
-
var OrgError = class extends Data.TaggedError("OrgError") {};
|
|
13477
|
-
function orgErrorFromCapxul(operation, error, cause = error) {
|
|
13478
|
-
return new OrgError({
|
|
13479
|
-
operation,
|
|
13480
|
-
publicCode: error.code,
|
|
13481
|
-
publicError: error,
|
|
13482
|
-
cause,
|
|
13483
|
-
...error.details === void 0 ? {} : { details: error.details }
|
|
13484
|
-
});
|
|
13485
|
-
}
|
|
13486
|
-
Context.Tag("@capxul/sdk/ports/OrgPort")();
|
|
13487
|
-
Context.Tag("@capxul/sdk/ports/OrgRolesDeploymentPort")();
|
|
13488
|
-
Context.Tag("@capxul/sdk/ports/OrgSpendPort")();
|
|
13489
|
-
//#endregion
|
|
13490
|
-
//#region ../../packages/sdk/src/adapters/org/parse.ts
|
|
13491
|
-
/**
|
|
13492
|
-
* Map a `WireOrg` + its (separately read) treasury `Account` into the branded
|
|
13493
|
-
* `OrgView`. The founder is the creator → `Owner` role within their own org
|
|
13494
|
-
* (D6/D7). Brands at the read edge: `orgId`, `safeAddress`.
|
|
13495
|
-
*/
|
|
13496
|
-
function brandOrgView(wire, treasury) {
|
|
13497
|
-
return {
|
|
13498
|
-
id: toOrgId(wire.orgId),
|
|
13499
|
-
name: wire.name,
|
|
13500
|
-
handle: wire.slug,
|
|
13501
|
-
safeAddress: toAddress(wire.safeAddress.toLowerCase()),
|
|
13502
|
-
role: "Owner",
|
|
13503
|
-
treasury
|
|
13504
|
-
};
|
|
13505
|
-
}
|
|
13506
|
-
/**
|
|
13507
|
-
* Build the Org treasury `Account` from the raw on-chain `balanceOf` integer
|
|
13508
|
-
* (the D3 RPC read). `available === balance` for a treasury with no envelope
|
|
13509
|
-
* partition yet (a fresh Org reads back $0).
|
|
13510
|
-
*/
|
|
13511
|
-
function brandOrgTreasury(input) {
|
|
13512
|
-
return {
|
|
13513
|
-
id: toAccountId(`account_${orgIdBody(input.orgId)}`),
|
|
13514
|
-
balance: input.money,
|
|
13515
|
-
available: input.money
|
|
13516
|
-
};
|
|
13517
|
-
}
|
|
13518
|
-
function brandOrgRole(wire) {
|
|
13519
|
-
return {
|
|
13520
|
-
orgId: toOrgId(wire.orgId),
|
|
13521
|
-
label: wire.label,
|
|
13522
|
-
roleKey: toRoleKey(wire.roleKey),
|
|
13523
|
-
definition: parseRoleDefinition(wire.definitionJson)
|
|
13524
|
-
};
|
|
13525
|
-
}
|
|
13526
|
-
function brandOrgMember(wire) {
|
|
13527
|
-
return {
|
|
13528
|
-
orgId: toOrgId(wire.orgId),
|
|
13529
|
-
email: toEmail(wire.email),
|
|
13530
|
-
name: wire.name,
|
|
13531
|
-
personalSafeAddress: wire.personalSafeAddress === null ? null : toAddress(wire.personalSafeAddress),
|
|
13532
|
-
role: wire.role,
|
|
13533
|
-
roleKey: wire.roleKey === null ? null : toRoleKey(wire.roleKey),
|
|
13534
|
-
status: wire.status,
|
|
13535
|
-
grantTxHash: wire.grantTxHash,
|
|
13536
|
-
revokeTxHash: wire.revokeTxHash
|
|
13537
|
-
};
|
|
13538
|
-
}
|
|
13539
|
-
function parseRoleDefinition(json) {
|
|
13540
|
-
let raw;
|
|
13541
|
-
try {
|
|
13542
|
-
const parsed = JSON.parse(json);
|
|
13543
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error("expected object");
|
|
13544
|
-
raw = parsed;
|
|
13545
|
-
} catch (err) {
|
|
13546
|
-
throw new Error(`Invalid role definition: malformed JSON - ${err instanceof Error ? err.message : String(err)}`);
|
|
13547
|
-
}
|
|
13548
|
-
if (typeof raw.label !== "string" || raw.label.trim().length === 0) throw new Error("Invalid role definition: missing label");
|
|
13549
|
-
return {
|
|
13550
|
-
label: raw.label,
|
|
13551
|
-
...raw.spend === void 0 ? {} : { spend: {
|
|
13552
|
-
...raw.spend.perTx === void 0 ? {} : { perTx: parseRoleMoney(raw.spend.perTx, "perTx") },
|
|
13553
|
-
...raw.spend.perDay === void 0 ? {} : { perDay: parseRoleMoney(raw.spend.perDay, "perDay") },
|
|
13554
|
-
...raw.spend.toRecipients === void 0 ? {} : { toRecipients: parseRoleRecipients(raw.spend.toRecipients) }
|
|
13555
|
-
} },
|
|
13556
|
-
...raw.subAccounts === void 0 ? {} : { subAccounts: parseRoleSubAccounts(raw.subAccounts) },
|
|
13557
|
-
...typeof raw.canManageMembers === "boolean" ? { canManageMembers: raw.canManageMembers } : {},
|
|
13558
|
-
...typeof raw.canManageRoles === "boolean" ? { canManageRoles: raw.canManageRoles } : {}
|
|
13559
|
-
};
|
|
13560
|
-
}
|
|
13561
|
-
function parseRoleMoney(raw, field) {
|
|
13562
|
-
if (typeof raw.currency !== "string" || typeof raw.value !== "string" || !/^\d+$/.test(raw.value) || raw.decimals !== 6) throw new Error(`Invalid role money: ${field}`);
|
|
13563
|
-
return {
|
|
13564
|
-
currency: toCurrencyCode(raw.currency),
|
|
13565
|
-
value: raw.value,
|
|
13566
|
-
decimals: raw.decimals
|
|
13567
|
-
};
|
|
13568
|
-
}
|
|
13569
|
-
function parseRoleRecipients(raw) {
|
|
13570
|
-
if (raw === "anyone") return "anyone";
|
|
13571
|
-
if (!Array.isArray(raw)) throw new Error("Invalid role definition: toRecipients must be \"anyone\" or an array");
|
|
13572
|
-
return raw.map((recipient) => {
|
|
13573
|
-
if (typeof recipient !== "string") throw new Error("Invalid role definition: toRecipients must be \"anyone\" or an array");
|
|
13574
|
-
return toAddress(recipient);
|
|
13575
|
-
});
|
|
13576
|
-
}
|
|
13577
|
-
function parseRoleSubAccounts(raw) {
|
|
13578
|
-
if (raw.scope === "all") return { scope: "all" };
|
|
13579
|
-
if (!Array.isArray(raw.scope)) throw new Error("Invalid role definition: subAccounts.scope must be \"all\" or an array");
|
|
13580
|
-
return { scope: raw.scope.map((subAccountId) => {
|
|
13581
|
-
if (typeof subAccountId !== "string") throw new Error("Invalid role definition: subAccounts.scope must be \"all\" or an array");
|
|
13582
|
-
return toSubAccountId(subAccountId);
|
|
13583
|
-
}) };
|
|
13584
|
-
}
|
|
13585
|
-
/** Strip the `org_` prefix + non-alphanumerics so the body re-seeds `account_`. */
|
|
13586
|
-
function orgIdBody(orgId) {
|
|
13587
|
-
const underscore = orgId.indexOf("_");
|
|
13588
|
-
const cleaned = (underscore < 0 ? orgId : orgId.slice(underscore + 1)).replace(/[^0-9A-Za-z]/g, "");
|
|
13589
|
-
return cleaned.length > 0 ? cleaned : "0";
|
|
13590
|
-
}
|
|
13591
14295
|
toDurationMs(12e4);
|
|
13592
14296
|
/** The viem `entryPoint` v0.7 descriptor shared by every live deploy. */
|
|
13593
14297
|
const ENTRY_POINT_07 = {
|
|
@@ -13650,8 +14354,8 @@ const orgListMembersByOrgIdQuery = makeFunctionReference("org/queries:listMember
|
|
|
13650
14354
|
//#endregion
|
|
13651
14355
|
//#region ../../packages/sdk/src/__e2e__/live-org-deployment.ts
|
|
13652
14356
|
/**
|
|
13653
|
-
* E2E ONLY: live Base Sepolia Org Safe deploy adapter (
|
|
13654
|
-
* `
|
|
14357
|
+
* E2E ONLY: live Base Sepolia Org Safe deploy adapter (see
|
|
14358
|
+
* `packages/sdk/CONTEXT.md`). Implements the
|
|
13655
14359
|
* SDK-side `OrgPort` for the S1 capstone. Do not import from production SDK
|
|
13656
14360
|
* code — it reads deploy env (`DEPLOYER_PRIVATE_KEY`, `BASE_SEPOLIA_RPC_URL`)
|
|
13657
14361
|
* and sends real on-chain transactions.
|
|
@@ -13714,67 +14418,6 @@ const erc20BalanceOfAbi = [{
|
|
|
13714
14418
|
type: "uint256"
|
|
13715
14419
|
}]
|
|
13716
14420
|
}];
|
|
13717
|
-
const safeExecTransactionAbi = [{
|
|
13718
|
-
type: "function",
|
|
13719
|
-
name: "execTransaction",
|
|
13720
|
-
stateMutability: "payable",
|
|
13721
|
-
inputs: [
|
|
13722
|
-
{
|
|
13723
|
-
name: "to",
|
|
13724
|
-
type: "address"
|
|
13725
|
-
},
|
|
13726
|
-
{
|
|
13727
|
-
name: "value",
|
|
13728
|
-
type: "uint256"
|
|
13729
|
-
},
|
|
13730
|
-
{
|
|
13731
|
-
name: "data",
|
|
13732
|
-
type: "bytes"
|
|
13733
|
-
},
|
|
13734
|
-
{
|
|
13735
|
-
name: "operation",
|
|
13736
|
-
type: "uint8"
|
|
13737
|
-
},
|
|
13738
|
-
{
|
|
13739
|
-
name: "safeTxGas",
|
|
13740
|
-
type: "uint256"
|
|
13741
|
-
},
|
|
13742
|
-
{
|
|
13743
|
-
name: "baseGas",
|
|
13744
|
-
type: "uint256"
|
|
13745
|
-
},
|
|
13746
|
-
{
|
|
13747
|
-
name: "gasPrice",
|
|
13748
|
-
type: "uint256"
|
|
13749
|
-
},
|
|
13750
|
-
{
|
|
13751
|
-
name: "gasToken",
|
|
13752
|
-
type: "address"
|
|
13753
|
-
},
|
|
13754
|
-
{
|
|
13755
|
-
name: "refundReceiver",
|
|
13756
|
-
type: "address"
|
|
13757
|
-
},
|
|
13758
|
-
{
|
|
13759
|
-
name: "signatures",
|
|
13760
|
-
type: "bytes"
|
|
13761
|
-
}
|
|
13762
|
-
],
|
|
13763
|
-
outputs: [{
|
|
13764
|
-
name: "success",
|
|
13765
|
-
type: "bool"
|
|
13766
|
-
}]
|
|
13767
|
-
}];
|
|
13768
|
-
const multiSendAbi = [{
|
|
13769
|
-
type: "function",
|
|
13770
|
-
name: "multiSend",
|
|
13771
|
-
stateMutability: "payable",
|
|
13772
|
-
inputs: [{
|
|
13773
|
-
name: "transactions",
|
|
13774
|
-
type: "bytes"
|
|
13775
|
-
}],
|
|
13776
|
-
outputs: []
|
|
13777
|
-
}];
|
|
13778
14421
|
const rolesExecTransactionWithRoleVerificationAbi = [{
|
|
13779
14422
|
type: "function",
|
|
13780
14423
|
name: "execTransactionWithRole",
|
|
@@ -13815,9 +14458,7 @@ const rolesExecTransactionWithRoleVerificationAbi = [{
|
|
|
13815
14458
|
inputs: []
|
|
13816
14459
|
}];
|
|
13817
14460
|
const DEFAULT_RECEIPT_TIMEOUT_MS = 12e4;
|
|
13818
|
-
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
13819
14461
|
const SAFE_OPERATION_CALL = 0;
|
|
13820
|
-
const SAFE_OPERATION_DELEGATECALL = 1;
|
|
13821
14462
|
const ASSIGN_ROLES_PERMISSION = "zodiac.roles.assignRoles";
|
|
13822
14463
|
var LiveOrgDeploymentAdapter = class {
|
|
13823
14464
|
#convex;
|
|
@@ -13998,7 +14639,7 @@ var LiveOrgDeploymentAdapter = class {
|
|
|
13998
14639
|
});
|
|
13999
14640
|
const [deployModuleCall, ...orgSafeCalls] = deployment.calls;
|
|
14000
14641
|
if (deployModuleCall === void 0) throw Errors.providerError("permissionless-org-roles-deployment", "deployRoles", "Zodiac Roles deployment builder returned no calls");
|
|
14001
|
-
const calls = [deployModuleCall,
|
|
14642
|
+
const calls = [deployModuleCall, buildSafeMultiSendExecTransactionCall({
|
|
14002
14643
|
safeAddress: toViemHexAddress(wire.safeAddress),
|
|
14003
14644
|
ownerAddress: toViemHexAddress(wire.ownerPersonalSafeAddress),
|
|
14004
14645
|
calls: orgSafeCalls
|
|
@@ -14192,7 +14833,7 @@ async function isContractDeployed(publicClient, address) {
|
|
|
14192
14833
|
return code !== void 0 && code !== "0x";
|
|
14193
14834
|
}
|
|
14194
14835
|
function wireToOrgView(wire, treasury) {
|
|
14195
|
-
return brandOrgView(wire, treasury);
|
|
14836
|
+
return brandOrgView(wire, treasury, "Owner");
|
|
14196
14837
|
}
|
|
14197
14838
|
function deriveLiveSpendAuthority(input) {
|
|
14198
14839
|
if (input.org === null) return inactiveSpendAuthority();
|
|
@@ -14221,9 +14862,9 @@ function spendAuthorityFromRole(role, roleLabel) {
|
|
|
14221
14862
|
activeMember: true,
|
|
14222
14863
|
subAccountBalanceRaw: "100000000000",
|
|
14223
14864
|
recipients: spend?.toRecipients ?? "anyone",
|
|
14224
|
-
subAccounts: subAccountScope ===
|
|
14865
|
+
subAccounts: subAccountScope === "all" ? { scope: "all" } : {
|
|
14225
14866
|
scope: "only",
|
|
14226
|
-
subAccountIds: subAccountScope
|
|
14867
|
+
subAccountIds: subAccountScope?.map(toSubAccountId) ?? []
|
|
14227
14868
|
},
|
|
14228
14869
|
...spend?.perTx === void 0 ? {} : { perTxCapRaw: spend.perTx.value },
|
|
14229
14870
|
...spend?.perDay === void 0 ? {} : { perDayCapRaw: spend.perDay.value },
|
|
@@ -14267,51 +14908,6 @@ async function verifyOrgRoleRevokedOnChain(input) {
|
|
|
14267
14908
|
}
|
|
14268
14909
|
throw Errors.providerError("permissionless-org-roles", "verifyRevoke", "revoked member can still execute its former Zodiac role");
|
|
14269
14910
|
}
|
|
14270
|
-
function buildOrgSafeExecTransactionCall(input) {
|
|
14271
|
-
const data = encodeFunctionData({
|
|
14272
|
-
abi: multiSendAbi,
|
|
14273
|
-
functionName: "multiSend",
|
|
14274
|
-
args: [concat(input.calls.map(encodeMultiSendCallTransaction))]
|
|
14275
|
-
});
|
|
14276
|
-
return {
|
|
14277
|
-
to: input.safeAddress,
|
|
14278
|
-
data: encodeFunctionData({
|
|
14279
|
-
abi: safeExecTransactionAbi,
|
|
14280
|
-
functionName: "execTransaction",
|
|
14281
|
-
args: [
|
|
14282
|
-
MULTI_SEND,
|
|
14283
|
-
0n,
|
|
14284
|
-
data,
|
|
14285
|
-
SAFE_OPERATION_DELEGATECALL,
|
|
14286
|
-
0n,
|
|
14287
|
-
0n,
|
|
14288
|
-
0n,
|
|
14289
|
-
ZERO_ADDRESS,
|
|
14290
|
-
ZERO_ADDRESS,
|
|
14291
|
-
prevalidatedSafeSignature(input.ownerAddress)
|
|
14292
|
-
]
|
|
14293
|
-
}),
|
|
14294
|
-
value: 0n
|
|
14295
|
-
};
|
|
14296
|
-
}
|
|
14297
|
-
function encodeMultiSendCallTransaction(call) {
|
|
14298
|
-
return encodePacked([
|
|
14299
|
-
"uint8",
|
|
14300
|
-
"address",
|
|
14301
|
-
"uint256",
|
|
14302
|
-
"uint256",
|
|
14303
|
-
"bytes"
|
|
14304
|
-
], [
|
|
14305
|
-
SAFE_OPERATION_CALL,
|
|
14306
|
-
call.to,
|
|
14307
|
-
call.value,
|
|
14308
|
-
BigInt((call.data.length - 2) / 2),
|
|
14309
|
-
call.data
|
|
14310
|
-
]);
|
|
14311
|
-
}
|
|
14312
|
-
function prevalidatedSafeSignature(ownerAddress) {
|
|
14313
|
-
return `${padHex(ownerAddress, { size: 32 })}${"0".repeat(64)}01`;
|
|
14314
|
-
}
|
|
14315
14911
|
function requireActiveRole(roles, label) {
|
|
14316
14912
|
const role = roles.find((candidate) => candidate.status === "active" && candidate.label === label);
|
|
14317
14913
|
if (role === void 0) throw Errors.invalidInput("role", `active org role not found: ${label}`);
|
|
@@ -14580,28 +15176,36 @@ async function buildSponsoredSafeUserOp(input) {
|
|
|
14580
15176
|
};
|
|
14581
15177
|
return {
|
|
14582
15178
|
userOp,
|
|
14583
|
-
digest:
|
|
14584
|
-
userOp
|
|
14585
|
-
sender: userOp.sender,
|
|
14586
|
-
nonce,
|
|
14587
|
-
...userOp.factory === void 0 ? {} : { factory: userOp.factory },
|
|
14588
|
-
...userOp.factoryData === void 0 ? {} : { factoryData: userOp.factoryData },
|
|
14589
|
-
callData: userOp.callData,
|
|
14590
|
-
callGasLimit: rpcQuantityToBigInt(userOp.callGasLimit, "callGasLimit"),
|
|
14591
|
-
verificationGasLimit: rpcQuantityToBigInt(userOp.verificationGasLimit, "verificationGasLimit"),
|
|
14592
|
-
preVerificationGas: rpcQuantityToBigInt(userOp.preVerificationGas, "preVerificationGas"),
|
|
14593
|
-
maxFeePerGas: rpcQuantityToBigInt(userOp.maxFeePerGas, "maxFeePerGas"),
|
|
14594
|
-
maxPriorityFeePerGas: rpcQuantityToBigInt(userOp.maxPriorityFeePerGas, "maxPriorityFeePerGas"),
|
|
14595
|
-
paymaster: userOp.paymaster,
|
|
14596
|
-
...userOp.paymasterVerificationGasLimit === void 0 ? {} : { paymasterVerificationGasLimit: rpcQuantityToBigInt(userOp.paymasterVerificationGasLimit, "paymasterVerificationGasLimit") },
|
|
14597
|
-
...userOp.paymasterPostOpGasLimit === void 0 ? {} : { paymasterPostOpGasLimit: rpcQuantityToBigInt(userOp.paymasterPostOpGasLimit, "paymasterPostOpGasLimit") },
|
|
14598
|
-
paymasterData: userOp.paymasterData
|
|
14599
|
-
},
|
|
15179
|
+
digest: deploymentUserOpDigest({
|
|
15180
|
+
userOp,
|
|
14600
15181
|
chainId
|
|
14601
15182
|
}),
|
|
14602
15183
|
safeAddress: sender
|
|
14603
15184
|
};
|
|
14604
15185
|
}
|
|
15186
|
+
/** Recompute the SafeOp digest from the exact wire operation submitted by a client. */
|
|
15187
|
+
function deploymentUserOpDigest(input) {
|
|
15188
|
+
const { userOp, chainId } = input;
|
|
15189
|
+
return safe4337SafeOpDigest({
|
|
15190
|
+
userOp: {
|
|
15191
|
+
sender: userOp.sender,
|
|
15192
|
+
nonce: rpcQuantityToBigInt(userOp.nonce, "nonce"),
|
|
15193
|
+
...userOp.factory === void 0 ? {} : { factory: userOp.factory },
|
|
15194
|
+
...userOp.factoryData === void 0 ? {} : { factoryData: userOp.factoryData },
|
|
15195
|
+
callData: userOp.callData,
|
|
15196
|
+
callGasLimit: rpcQuantityToBigInt(userOp.callGasLimit, "callGasLimit"),
|
|
15197
|
+
verificationGasLimit: rpcQuantityToBigInt(userOp.verificationGasLimit, "verificationGasLimit"),
|
|
15198
|
+
preVerificationGas: rpcQuantityToBigInt(userOp.preVerificationGas, "preVerificationGas"),
|
|
15199
|
+
maxFeePerGas: rpcQuantityToBigInt(userOp.maxFeePerGas, "maxFeePerGas"),
|
|
15200
|
+
maxPriorityFeePerGas: rpcQuantityToBigInt(userOp.maxPriorityFeePerGas, "maxPriorityFeePerGas"),
|
|
15201
|
+
paymaster: userOp.paymaster,
|
|
15202
|
+
...userOp.paymasterVerificationGasLimit === void 0 ? {} : { paymasterVerificationGasLimit: rpcQuantityToBigInt(userOp.paymasterVerificationGasLimit, "paymasterVerificationGasLimit") },
|
|
15203
|
+
...userOp.paymasterPostOpGasLimit === void 0 ? {} : { paymasterPostOpGasLimit: rpcQuantityToBigInt(userOp.paymasterPostOpGasLimit, "paymasterPostOpGasLimit") },
|
|
15204
|
+
paymasterData: userOp.paymasterData
|
|
15205
|
+
},
|
|
15206
|
+
chainId
|
|
15207
|
+
});
|
|
15208
|
+
}
|
|
14605
15209
|
//#endregion
|
|
14606
15210
|
//#region src/settlement-port.ts
|
|
14607
15211
|
const ADDRESS_RE$1 = /^0x[0-9a-fA-F]{40}$/;
|
|
@@ -15317,8 +15921,8 @@ async function executeCommitmentRedirect(input) {
|
|
|
15317
15921
|
*/
|
|
15318
15922
|
async function fetchCommitmentCreatedIdFromLogs(input) {
|
|
15319
15923
|
const { keccak256, toBytes } = await import("viem");
|
|
15320
|
-
const { fetchCommitmentCreatedLog } = await import("./alchemy-rpc-
|
|
15321
|
-
const { CAPXUL_PAYMENTS_ADDRESS } = await import("./src-
|
|
15924
|
+
const { fetchCommitmentCreatedLog } = await import("./alchemy-rpc-DRpULec2.mjs");
|
|
15925
|
+
const { CAPXUL_PAYMENTS_ADDRESS } = await import("./src-CIqRZpwl.mjs");
|
|
15322
15926
|
const topic0 = keccak256(toBytes("CommitmentCreated(uint256,address,address,address,uint256,uint48,uint48,uint48,bytes32,uint8)"));
|
|
15323
15927
|
const idTopic = (await fetchCommitmentCreatedLog({
|
|
15324
15928
|
chainId: input.chainId,
|