@capxul/mcp 1.0.0-alpha.17 → 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 +725 -311
- 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,22 @@ 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
|
|
1612
1628
|
//#region ../../packages/wire/src/observation-context.ts
|
|
1613
1629
|
/** Single bounded HTTP carrier used before a Convex action envelope exists. */
|
|
1614
1630
|
const OBSERVATION_CONTEXT_HEADER = "x-capxul-observation-context";
|
|
@@ -1642,10 +1658,6 @@ const FIELD_RULES = {
|
|
|
1642
1658
|
pattern: /^anon_[A-Za-z0-9-]+$/u
|
|
1643
1659
|
}
|
|
1644
1660
|
};
|
|
1645
|
-
const EMBEDDED_WALLET_MATERIAL = /0x[a-fA-F0-9]{40,}/u;
|
|
1646
|
-
const RAW_PRIVATE_KEY_MATERIAL = /(?:^|[^a-fA-F0-9])[a-fA-F0-9]{64}(?:$|[^a-fA-F0-9])/u;
|
|
1647
|
-
const COMPACT_JWT = /eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/u;
|
|
1648
|
-
const KNOWN_CREDENTIAL_PREFIX = /(?:(?: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;
|
|
1649
1661
|
/**
|
|
1650
1662
|
* Copy only the canonical allowlist and silently omit malformed/sensitive
|
|
1651
1663
|
* values. Observation metadata is best effort and may never reject a domain
|
|
@@ -1672,9 +1684,6 @@ function isSafeField(field, value) {
|
|
|
1672
1684
|
const rule = FIELD_RULES[field];
|
|
1673
1685
|
return value.length > 0 && value.length <= rule.maxLength && value === value.trim() && !value.includes("://") && !containsSensitiveMaterial(value) && rule.pattern.test(value);
|
|
1674
1686
|
}
|
|
1675
|
-
function containsSensitiveMaterial(value) {
|
|
1676
|
-
return EMBEDDED_WALLET_MATERIAL.test(value) || RAW_PRIVATE_KEY_MATERIAL.test(value) || COMPACT_JWT.test(value) || KNOWN_CREDENTIAL_PREFIX.test(value);
|
|
1677
|
-
}
|
|
1678
1687
|
//#endregion
|
|
1679
1688
|
//#region src/payment-wire.ts
|
|
1680
1689
|
const MONEY_RE$1 = /^\s*([0-9]+(?:\.[0-9]+)?)\s+([A-Za-z][A-Za-z0-9]*)\s*$/;
|
|
@@ -5259,7 +5268,7 @@ async function recoverRawDigestSigner(input) {
|
|
|
5259
5268
|
}
|
|
5260
5269
|
//#endregion
|
|
5261
5270
|
//#region ../../packages/sdk/package.json
|
|
5262
|
-
var version = "1.0.0-alpha.
|
|
5271
|
+
var version = "1.0.0-alpha.18";
|
|
5263
5272
|
//#endregion
|
|
5264
5273
|
//#region ../../packages/sdk/src/ports/auth-client.ts
|
|
5265
5274
|
var AuthClientError = class extends Data.TaggedError("AuthClientError") {};
|
|
@@ -6934,7 +6943,7 @@ function fromWei(rawBalance, decimals, currency) {
|
|
|
6934
6943
|
}
|
|
6935
6944
|
//#endregion
|
|
6936
6945
|
//#region ../../packages/sdk/src/adapters/account-read/ConvexAccountAdapter.ts
|
|
6937
|
-
const DEFAULT_FUNCTIONS$
|
|
6946
|
+
const DEFAULT_FUNCTIONS$5 = {
|
|
6938
6947
|
readBalance: makeFunctionReference("account/actions:readBalance"),
|
|
6939
6948
|
faucetMint: makeFunctionReference("account/actions:faucetMint")
|
|
6940
6949
|
};
|
|
@@ -6943,7 +6952,7 @@ var ConvexAccountAdapter = class {
|
|
|
6943
6952
|
#fns;
|
|
6944
6953
|
constructor(deps) {
|
|
6945
6954
|
this.#convex = deps.convex;
|
|
6946
|
-
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$
|
|
6955
|
+
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$5;
|
|
6947
6956
|
}
|
|
6948
6957
|
readBalance(input) {
|
|
6949
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))));
|
|
@@ -6996,7 +7005,7 @@ function subAccountErrorFromCapxul(operation, error, cause = error) {
|
|
|
6996
7005
|
var SubAccountPortTag = class extends Context.Tag("@capxul/sdk/ports/SubAccountPort")() {};
|
|
6997
7006
|
//#endregion
|
|
6998
7007
|
//#region ../../packages/sdk/src/adapters/sub-account/ConvexSubAccountAdapter.ts
|
|
6999
|
-
const DEFAULT_FUNCTIONS$
|
|
7008
|
+
const DEFAULT_FUNCTIONS$4 = {
|
|
7000
7009
|
create: makeFunctionReference("subAccount/mutations:create"),
|
|
7001
7010
|
get: makeFunctionReference("subAccount/queries:get"),
|
|
7002
7011
|
list: makeFunctionReference("subAccount/queries:list"),
|
|
@@ -7011,7 +7020,7 @@ var ConvexSubAccountAdapter = class {
|
|
|
7011
7020
|
constructor(deps) {
|
|
7012
7021
|
this.#convex = deps.convex;
|
|
7013
7022
|
this.#chainId = deps.chainId;
|
|
7014
|
-
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$
|
|
7023
|
+
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$4;
|
|
7015
7024
|
}
|
|
7016
7025
|
create(input) {
|
|
7017
7026
|
return this.#runMutation("create", this.#fns.create, {
|
|
@@ -7095,7 +7104,7 @@ function smartAccountErrorFromCapxul(operation, error, cause = error) {
|
|
|
7095
7104
|
var SmartAccountPortTag = class extends Context.Tag("@capxul/sdk/ports/SmartAccountPort")() {};
|
|
7096
7105
|
//#endregion
|
|
7097
7106
|
//#region ../../packages/sdk/src/adapters/smart-account/ConvexSmartAccountAdapter.ts
|
|
7098
|
-
const DEFAULT_FUNCTIONS$
|
|
7107
|
+
const DEFAULT_FUNCTIONS$3 = {
|
|
7099
7108
|
loadByAuthUserId: makeFunctionReference("smartAccount/queries:loadByAuthUserId"),
|
|
7100
7109
|
loadBySmartAccountAddress: makeFunctionReference("smartAccount/queries:loadBySmartAccountAddress"),
|
|
7101
7110
|
provision: makeFunctionReference("smartAccount/mutations:provision"),
|
|
@@ -7107,7 +7116,7 @@ var ConvexSmartAccountAdapter = class {
|
|
|
7107
7116
|
#fns;
|
|
7108
7117
|
constructor(deps) {
|
|
7109
7118
|
this.#convex = deps.convex;
|
|
7110
|
-
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$
|
|
7119
|
+
this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$3;
|
|
7111
7120
|
}
|
|
7112
7121
|
loadByAuthUserId(authUserId) {
|
|
7113
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))));
|
|
@@ -7182,6 +7191,424 @@ function smartAccountErrorFromUnknown(operation, cause) {
|
|
|
7182
7191
|
toAddress("0xa6b71e26c5e0845f74c812102ca7114b6a896ab2");
|
|
7183
7192
|
keccak256("0x");
|
|
7184
7193
|
//#endregion
|
|
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")
|
|
7321
|
+
};
|
|
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
|
|
7185
7612
|
//#region ../../packages/observability/src/index.ts
|
|
7186
7613
|
const PII = Schema.String.pipe(Schema.brand("PII"));
|
|
7187
7614
|
const OptionalString = Schema.optional(Schema.String);
|
|
@@ -10668,13 +11095,83 @@ function listOrgsProgram() {
|
|
|
10668
11095
|
});
|
|
10669
11096
|
}
|
|
10670
11097
|
//#endregion
|
|
10671
|
-
//#region ../../packages/sdk/src/client/org.ts
|
|
10672
|
-
|
|
10673
|
-
|
|
10674
|
-
|
|
10675
|
-
|
|
10676
|
-
|
|
10677
|
-
|
|
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
|
|
11168
|
+
//#region ../../packages/sdk/src/client/org.ts
|
|
11169
|
+
/**
|
|
11170
|
+
* Org method surface (canon §C2/§C3, D13). S1 (#274) wires `createOrg` /
|
|
11171
|
+
* `orgs` / `treasury` to their Effect programs (`org-deps.ts`); the S2→S4
|
|
11172
|
+
* member/role/spend verbs stay `Errors.notImplemented("org", "<verb>")` until
|
|
11173
|
+
* their slices land. The entity-scoped bundle is constructed per `org(orgId)`
|
|
11174
|
+
* call (D13 — explicit scoping, no shared mutable "active org" state); the
|
|
10678
11175
|
* closed-over `orgId` is the only entity reference.
|
|
10679
11176
|
*/
|
|
10680
11177
|
function makeOrgMethods(deps) {
|
|
@@ -10716,6 +11213,36 @@ function makeOrgMethods(deps) {
|
|
|
10716
11213
|
},
|
|
10717
11214
|
...convexCall === void 0 ? {} : { convexCall }
|
|
10718
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
|
+
},
|
|
10719
11246
|
profile: {
|
|
10720
11247
|
get(_options) {
|
|
10721
11248
|
if (_options?.signal?.aborted) return Promise.resolve({
|
|
@@ -10749,12 +11276,12 @@ function makeOrgMethods(deps) {
|
|
|
10749
11276
|
ok: false,
|
|
10750
11277
|
error: treasury.error
|
|
10751
11278
|
};
|
|
10752
|
-
const
|
|
10753
|
-
if (!
|
|
11279
|
+
const orgList = await toCapxulResult(listOrgsProgram(), layer);
|
|
11280
|
+
if (!orgList.ok) return {
|
|
10754
11281
|
ok: false,
|
|
10755
|
-
error:
|
|
11282
|
+
error: orgList.error
|
|
10756
11283
|
};
|
|
10757
|
-
const org =
|
|
11284
|
+
const org = orgList.value.find((candidate) => candidate.id === orgId);
|
|
10758
11285
|
return {
|
|
10759
11286
|
ok: true,
|
|
10760
11287
|
value: {
|
|
@@ -10942,7 +11469,6 @@ function normalizePaymentTiming(payment) {
|
|
|
10942
11469
|
}
|
|
10943
11470
|
//#endregion
|
|
10944
11471
|
//#region ../../packages/sdk/src/flows/onboarding.ts
|
|
10945
|
-
const DEFAULT_ORG_TEMPLATE = "Startup";
|
|
10946
11472
|
async function runCompletePersonalOnboarding(ops, input) {
|
|
10947
11473
|
const validated = validatePersonalInput(input);
|
|
10948
11474
|
if (!validated.ok) return validated;
|
|
@@ -10966,11 +11492,13 @@ async function runCompletePersonalOnboarding(ops, input) {
|
|
|
10966
11492
|
value: { lifecycle: lifecycle.value }
|
|
10967
11493
|
};
|
|
10968
11494
|
}
|
|
10969
|
-
async function runCompleteOrganizationOnboarding(ops, input) {
|
|
11495
|
+
async function runCompleteOrganizationOnboarding(ops, input, options) {
|
|
10970
11496
|
const validated = validateOrganizationInput(input);
|
|
10971
11497
|
if (!validated.ok) return validated;
|
|
10972
11498
|
const session = await ops.currentSession();
|
|
10973
11499
|
if (session === null) return fail(Errors.notAuthenticated());
|
|
11500
|
+
const setup = ops.organizationSetup;
|
|
11501
|
+
if (setup === void 0) return fail(Errors.notImplemented("organizationSetup", "completeOrganization"));
|
|
10974
11502
|
const written = await ops.completeIdentityOnboarding({
|
|
10975
11503
|
authUserId: session.authUserId,
|
|
10976
11504
|
email: session.email,
|
|
@@ -10978,22 +11506,18 @@ async function runCompleteOrganizationOnboarding(ops, input) {
|
|
|
10978
11506
|
country: validated.value.country
|
|
10979
11507
|
});
|
|
10980
11508
|
if (!written.ok) return fail(written.error);
|
|
10981
|
-
const
|
|
10982
|
-
if (!provisioned.ok) return fail(provisioned.error);
|
|
10983
|
-
const org = await ops.createOrg({
|
|
11509
|
+
const started = await setup.startOrResume({
|
|
10984
11510
|
name: validated.value.organizationName,
|
|
10985
11511
|
handle: validated.value.handle,
|
|
10986
|
-
template: DEFAULT_ORG_TEMPLATE,
|
|
10987
11512
|
country: validated.value.country
|
|
10988
11513
|
});
|
|
10989
|
-
if (!
|
|
10990
|
-
|
|
10991
|
-
|
|
10992
|
-
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;
|
|
10993
11517
|
return {
|
|
10994
11518
|
ok: true,
|
|
10995
11519
|
value: {
|
|
10996
|
-
|
|
11520
|
+
orgId: started.value.orgId,
|
|
10997
11521
|
lifecycle: lifecycle.value
|
|
10998
11522
|
}
|
|
10999
11523
|
};
|
|
@@ -11084,8 +11608,7 @@ function fail(error) {
|
|
|
11084
11608
|
* Onboarding method surface. The thin namespace over the `flows/onboarding.ts`
|
|
11085
11609
|
* choreography: it adds the `signal`-abort pre-check and delegates to the run
|
|
11086
11610
|
* functions. The `OnboardingOps` seam is supplied by `assembleCapxulClient`
|
|
11087
|
-
* (real ops
|
|
11088
|
-
* (in-memory double).
|
|
11611
|
+
* (real identity/Account ops plus Organization setup capability) or by tests.
|
|
11089
11612
|
*/
|
|
11090
11613
|
function makeOnboardingMethods(ops) {
|
|
11091
11614
|
return {
|
|
@@ -11101,7 +11624,7 @@ function makeOnboardingMethods(ops) {
|
|
|
11101
11624
|
ok: false,
|
|
11102
11625
|
error: Errors.cancelled({ operation: "onboarding.completeOrganization" })
|
|
11103
11626
|
});
|
|
11104
|
-
return runCompleteOrganizationOnboarding(ops, input);
|
|
11627
|
+
return runCompleteOrganizationOnboarding(ops, input, options);
|
|
11105
11628
|
}
|
|
11106
11629
|
};
|
|
11107
11630
|
}
|
|
@@ -11288,7 +11811,8 @@ function assembleCapxulClient(input) {
|
|
|
11288
11811
|
...selectedOrgPort === void 0 ? {} : { orgPort: selectedOrgPort },
|
|
11289
11812
|
...input.orgRolesDeploymentPort === void 0 ? {} : { orgRolesDeploymentPort: input.orgRolesDeploymentPort },
|
|
11290
11813
|
...input.orgSpendPort === void 0 ? {} : { orgSpendPort: input.orgSpendPort },
|
|
11291
|
-
convexCall: input.ports.convexCall
|
|
11814
|
+
convexCall: input.ports.convexCall,
|
|
11815
|
+
...input.organizationSetup === void 0 ? {} : { organizationSetup: input.organizationSetup }
|
|
11292
11816
|
});
|
|
11293
11817
|
if (selectedOrgPort !== void 0) detectPendingOrgInvitations = async () => {
|
|
11294
11818
|
await orgMethods.orgs.detectAndAcceptPendingInvitations();
|
|
@@ -11311,7 +11835,7 @@ function assembleCapxulClient(input) {
|
|
|
11311
11835
|
triggerProvisioning: () => account._internal.provision(),
|
|
11312
11836
|
kickProvisioning: () => kickProvisioning?.(),
|
|
11313
11837
|
readLifecycle: () => account.getLifecycle(),
|
|
11314
|
-
|
|
11838
|
+
...input.organizationSetup === void 0 ? {} : { organizationSetup: input.organizationSetup }
|
|
11315
11839
|
});
|
|
11316
11840
|
return {
|
|
11317
11841
|
auth,
|
|
@@ -11351,6 +11875,34 @@ function assembleCapxulClient(input) {
|
|
|
11351
11875
|
//#endregion
|
|
11352
11876
|
//#region ../../packages/sdk/src/observation.ts
|
|
11353
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
|
+
}
|
|
11354
11906
|
/** @internal Decorates public client method bundles at the owning SDK boundary. */
|
|
11355
11907
|
function observeSdkClient(client, adapter) {
|
|
11356
11908
|
if (adapter === void 0) return client;
|
|
@@ -11454,7 +12006,7 @@ function report(adapter, kind, operation, cause, invocationContext) {
|
|
|
11454
12006
|
}
|
|
11455
12007
|
function resolveAdapterContext(adapter) {
|
|
11456
12008
|
try {
|
|
11457
|
-
return
|
|
12009
|
+
return adapter.resolveContext?.();
|
|
11458
12010
|
} catch {
|
|
11459
12011
|
return;
|
|
11460
12012
|
}
|
|
@@ -11500,6 +12052,43 @@ function isCapxulResult(value) {
|
|
|
11500
12052
|
function isFailedResult(value) {
|
|
11501
12053
|
return isCapxulResult(value) && value.ok === false && "error" in value;
|
|
11502
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
|
+
}
|
|
11503
12092
|
const SDK_VERSION = version;
|
|
11504
12093
|
const collectProductionFlowPorts = Effect.gen(function* () {
|
|
11505
12094
|
const authClient = yield* AuthClientPortTag;
|
|
@@ -11787,7 +12376,7 @@ async function createCapxulClient(input) {
|
|
|
11787
12376
|
...input.authBaseUrl === void 0 ? {} : { override: input.authBaseUrl }
|
|
11788
12377
|
});
|
|
11789
12378
|
let signer = input.signer;
|
|
11790
|
-
if (signer === void 0 &&
|
|
12379
|
+
if (signer === void 0 && runtime === "browser") signer = createOpenfortBrowserSignerFromBootstrap({
|
|
11791
12380
|
...adapters.value.bootstrap,
|
|
11792
12381
|
authBaseUrl: resolvedAuthBaseUrl
|
|
11793
12382
|
});
|
|
@@ -11797,23 +12386,33 @@ async function createCapxulClient(input) {
|
|
|
11797
12386
|
authCache: adapters.value.ports.authCache,
|
|
11798
12387
|
requirement: input.requirement ?? "none",
|
|
11799
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
|
+
}) },
|
|
11800
12394
|
...input.signal === void 0 ? {} : { signal: input.signal },
|
|
11801
12395
|
...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs },
|
|
11802
12396
|
invokeTimeoutMs: input.invokeTimeoutMs ?? 3e4
|
|
11803
12397
|
}), signer);
|
|
11804
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;
|
|
11805
12413
|
return {
|
|
11806
12414
|
ok: true,
|
|
11807
|
-
value: observeSdkClient(
|
|
11808
|
-
...client,
|
|
11809
|
-
_internal: {
|
|
11810
|
-
...client._internal,
|
|
11811
|
-
close: async () => {
|
|
11812
|
-
if ("resetSession" in (signer ?? {})) signer.resetSession();
|
|
11813
|
-
await upstreamClose();
|
|
11814
|
-
}
|
|
11815
|
-
}
|
|
11816
|
-
}, input.observation)
|
|
12415
|
+
value: observeSdkClient(value, composeObservationAdapters(input.observation, relay))
|
|
11817
12416
|
};
|
|
11818
12417
|
} catch (cause) {
|
|
11819
12418
|
await adapters.value.close().catch(() => void 0);
|
|
@@ -11855,6 +12454,38 @@ function resolveInput(input) {
|
|
|
11855
12454
|
};
|
|
11856
12455
|
}
|
|
11857
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
|
+
}
|
|
11858
12489
|
function detectRuntime() {
|
|
11859
12490
|
const globalAny = globalThis;
|
|
11860
12491
|
return globalAny.window !== void 0 || globalAny.document !== void 0 ? "browser" : "node";
|
|
@@ -12463,7 +13094,7 @@ async function signUserOperation(parameters) {
|
|
|
12463
13094
|
}
|
|
12464
13095
|
//#endregion
|
|
12465
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
|
|
12466
|
-
const multiSendAbi
|
|
13097
|
+
const multiSendAbi = [{
|
|
12467
13098
|
inputs: [{
|
|
12468
13099
|
internalType: "bytes",
|
|
12469
13100
|
name: "transactions",
|
|
@@ -12947,7 +13578,7 @@ const encodeInternalTransaction = (tx) => {
|
|
|
12947
13578
|
};
|
|
12948
13579
|
const encodeMultiSend = (txs) => {
|
|
12949
13580
|
return encodeFunctionData({
|
|
12950
|
-
abi: multiSendAbi
|
|
13581
|
+
abi: multiSendAbi,
|
|
12951
13582
|
functionName: "multiSend",
|
|
12952
13583
|
args: [`0x${txs.map((tx) => encodeInternalTransaction(tx)).join("")}`]
|
|
12953
13584
|
});
|
|
@@ -13472,7 +14103,7 @@ async function toSafeSmartAccount(parameters) {
|
|
|
13472
14103
|
const data = decoded.args[2];
|
|
13473
14104
|
if (to === multiSendCallOnlyAddress) {
|
|
13474
14105
|
const dataToDecode = decodeFunctionData({
|
|
13475
|
-
abi: multiSendAbi
|
|
14106
|
+
abi: multiSendAbi,
|
|
13476
14107
|
data
|
|
13477
14108
|
}).args[0];
|
|
13478
14109
|
const transactions = [];
|
|
@@ -13661,123 +14292,6 @@ async function toSafeSmartAccount(parameters) {
|
|
|
13661
14292
|
}
|
|
13662
14293
|
});
|
|
13663
14294
|
}
|
|
13664
|
-
//#endregion
|
|
13665
|
-
//#region ../../packages/sdk/src/ports/org.ts
|
|
13666
|
-
var OrgError = class extends Data.TaggedError("OrgError") {};
|
|
13667
|
-
function orgErrorFromCapxul(operation, error, cause = error) {
|
|
13668
|
-
return new OrgError({
|
|
13669
|
-
operation,
|
|
13670
|
-
publicCode: error.code,
|
|
13671
|
-
publicError: error,
|
|
13672
|
-
cause,
|
|
13673
|
-
...error.details === void 0 ? {} : { details: error.details }
|
|
13674
|
-
});
|
|
13675
|
-
}
|
|
13676
|
-
Context.Tag("@capxul/sdk/ports/OrgPort")();
|
|
13677
|
-
Context.Tag("@capxul/sdk/ports/OrgRolesDeploymentPort")();
|
|
13678
|
-
Context.Tag("@capxul/sdk/ports/OrgSpendPort")();
|
|
13679
|
-
//#endregion
|
|
13680
|
-
//#region ../../packages/sdk/src/adapters/org/parse.ts
|
|
13681
|
-
/**
|
|
13682
|
-
* Map a `WireOrg` + its (separately read) treasury `Account` into the branded
|
|
13683
|
-
* `OrgView`. The founder is the creator → `Owner` role within their own org
|
|
13684
|
-
* (D6/D7). Brands at the read edge: `orgId`, `safeAddress`.
|
|
13685
|
-
*/
|
|
13686
|
-
function brandOrgView(wire, treasury) {
|
|
13687
|
-
return {
|
|
13688
|
-
id: toOrgId(wire.orgId),
|
|
13689
|
-
name: wire.name,
|
|
13690
|
-
handle: wire.slug,
|
|
13691
|
-
safeAddress: toAddress(wire.safeAddress.toLowerCase()),
|
|
13692
|
-
role: "Owner",
|
|
13693
|
-
treasury
|
|
13694
|
-
};
|
|
13695
|
-
}
|
|
13696
|
-
/**
|
|
13697
|
-
* Build the Org treasury `Account` from the raw on-chain `balanceOf` integer
|
|
13698
|
-
* (the D3 RPC read). `available === balance` for a treasury with no envelope
|
|
13699
|
-
* partition yet (a fresh Org reads back $0).
|
|
13700
|
-
*/
|
|
13701
|
-
function brandOrgTreasury(input) {
|
|
13702
|
-
return {
|
|
13703
|
-
id: toAccountId(`account_${orgIdBody(input.orgId)}`),
|
|
13704
|
-
balance: input.money,
|
|
13705
|
-
available: input.money
|
|
13706
|
-
};
|
|
13707
|
-
}
|
|
13708
|
-
function brandOrgRole(wire) {
|
|
13709
|
-
return {
|
|
13710
|
-
orgId: toOrgId(wire.orgId),
|
|
13711
|
-
label: wire.label,
|
|
13712
|
-
roleKey: toRoleKey(wire.roleKey),
|
|
13713
|
-
definition: parseRoleDefinition(wire.definitionJson)
|
|
13714
|
-
};
|
|
13715
|
-
}
|
|
13716
|
-
function brandOrgMember(wire) {
|
|
13717
|
-
return {
|
|
13718
|
-
orgId: toOrgId(wire.orgId),
|
|
13719
|
-
email: toEmail(wire.email),
|
|
13720
|
-
name: wire.name,
|
|
13721
|
-
personalSafeAddress: wire.personalSafeAddress === null ? null : toAddress(wire.personalSafeAddress),
|
|
13722
|
-
role: wire.role,
|
|
13723
|
-
roleKey: wire.roleKey === null ? null : toRoleKey(wire.roleKey),
|
|
13724
|
-
status: wire.status,
|
|
13725
|
-
grantTxHash: wire.grantTxHash,
|
|
13726
|
-
revokeTxHash: wire.revokeTxHash
|
|
13727
|
-
};
|
|
13728
|
-
}
|
|
13729
|
-
function parseRoleDefinition(json) {
|
|
13730
|
-
let raw;
|
|
13731
|
-
try {
|
|
13732
|
-
const parsed = JSON.parse(json);
|
|
13733
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error("expected object");
|
|
13734
|
-
raw = parsed;
|
|
13735
|
-
} catch (err) {
|
|
13736
|
-
throw new Error(`Invalid role definition: malformed JSON - ${err instanceof Error ? err.message : String(err)}`);
|
|
13737
|
-
}
|
|
13738
|
-
if (typeof raw.label !== "string" || raw.label.trim().length === 0) throw new Error("Invalid role definition: missing label");
|
|
13739
|
-
return {
|
|
13740
|
-
label: raw.label,
|
|
13741
|
-
...raw.spend === void 0 ? {} : { spend: {
|
|
13742
|
-
...raw.spend.perTx === void 0 ? {} : { perTx: parseRoleMoney(raw.spend.perTx, "perTx") },
|
|
13743
|
-
...raw.spend.perDay === void 0 ? {} : { perDay: parseRoleMoney(raw.spend.perDay, "perDay") },
|
|
13744
|
-
...raw.spend.toRecipients === void 0 ? {} : { toRecipients: parseRoleRecipients(raw.spend.toRecipients) }
|
|
13745
|
-
} },
|
|
13746
|
-
...raw.subAccounts === void 0 ? {} : { subAccounts: parseRoleSubAccounts(raw.subAccounts) },
|
|
13747
|
-
...typeof raw.canManageMembers === "boolean" ? { canManageMembers: raw.canManageMembers } : {},
|
|
13748
|
-
...typeof raw.canManageRoles === "boolean" ? { canManageRoles: raw.canManageRoles } : {}
|
|
13749
|
-
};
|
|
13750
|
-
}
|
|
13751
|
-
function parseRoleMoney(raw, field) {
|
|
13752
|
-
if (typeof raw.currency !== "string" || typeof raw.value !== "string" || !/^\d+$/.test(raw.value) || raw.decimals !== 6) throw new Error(`Invalid role money: ${field}`);
|
|
13753
|
-
return {
|
|
13754
|
-
currency: toCurrencyCode(raw.currency),
|
|
13755
|
-
value: raw.value,
|
|
13756
|
-
decimals: raw.decimals
|
|
13757
|
-
};
|
|
13758
|
-
}
|
|
13759
|
-
function parseRoleRecipients(raw) {
|
|
13760
|
-
if (raw === "anyone") return "anyone";
|
|
13761
|
-
if (!Array.isArray(raw)) throw new Error("Invalid role definition: toRecipients must be \"anyone\" or an array");
|
|
13762
|
-
return raw.map((recipient) => {
|
|
13763
|
-
if (typeof recipient !== "string") throw new Error("Invalid role definition: toRecipients must be \"anyone\" or an array");
|
|
13764
|
-
return toAddress(recipient);
|
|
13765
|
-
});
|
|
13766
|
-
}
|
|
13767
|
-
function parseRoleSubAccounts(raw) {
|
|
13768
|
-
if (raw.scope === "all") return { scope: "all" };
|
|
13769
|
-
if (!Array.isArray(raw.scope)) throw new Error("Invalid role definition: subAccounts.scope must be \"all\" or an array");
|
|
13770
|
-
return { scope: raw.scope.map((subAccountId) => {
|
|
13771
|
-
if (typeof subAccountId !== "string") throw new Error("Invalid role definition: subAccounts.scope must be \"all\" or an array");
|
|
13772
|
-
return toSubAccountId(subAccountId);
|
|
13773
|
-
}) };
|
|
13774
|
-
}
|
|
13775
|
-
/** Strip the `org_` prefix + non-alphanumerics so the body re-seeds `account_`. */
|
|
13776
|
-
function orgIdBody(orgId) {
|
|
13777
|
-
const underscore = orgId.indexOf("_");
|
|
13778
|
-
const cleaned = (underscore < 0 ? orgId : orgId.slice(underscore + 1)).replace(/[^0-9A-Za-z]/g, "");
|
|
13779
|
-
return cleaned.length > 0 ? cleaned : "0";
|
|
13780
|
-
}
|
|
13781
14295
|
toDurationMs(12e4);
|
|
13782
14296
|
/** The viem `entryPoint` v0.7 descriptor shared by every live deploy. */
|
|
13783
14297
|
const ENTRY_POINT_07 = {
|
|
@@ -13840,8 +14354,8 @@ const orgListMembersByOrgIdQuery = makeFunctionReference("org/queries:listMember
|
|
|
13840
14354
|
//#endregion
|
|
13841
14355
|
//#region ../../packages/sdk/src/__e2e__/live-org-deployment.ts
|
|
13842
14356
|
/**
|
|
13843
|
-
* E2E ONLY: live Base Sepolia Org Safe deploy adapter (
|
|
13844
|
-
* `
|
|
14357
|
+
* E2E ONLY: live Base Sepolia Org Safe deploy adapter (see
|
|
14358
|
+
* `packages/sdk/CONTEXT.md`). Implements the
|
|
13845
14359
|
* SDK-side `OrgPort` for the S1 capstone. Do not import from production SDK
|
|
13846
14360
|
* code — it reads deploy env (`DEPLOYER_PRIVATE_KEY`, `BASE_SEPOLIA_RPC_URL`)
|
|
13847
14361
|
* and sends real on-chain transactions.
|
|
@@ -13904,67 +14418,6 @@ const erc20BalanceOfAbi = [{
|
|
|
13904
14418
|
type: "uint256"
|
|
13905
14419
|
}]
|
|
13906
14420
|
}];
|
|
13907
|
-
const safeExecTransactionAbi = [{
|
|
13908
|
-
type: "function",
|
|
13909
|
-
name: "execTransaction",
|
|
13910
|
-
stateMutability: "payable",
|
|
13911
|
-
inputs: [
|
|
13912
|
-
{
|
|
13913
|
-
name: "to",
|
|
13914
|
-
type: "address"
|
|
13915
|
-
},
|
|
13916
|
-
{
|
|
13917
|
-
name: "value",
|
|
13918
|
-
type: "uint256"
|
|
13919
|
-
},
|
|
13920
|
-
{
|
|
13921
|
-
name: "data",
|
|
13922
|
-
type: "bytes"
|
|
13923
|
-
},
|
|
13924
|
-
{
|
|
13925
|
-
name: "operation",
|
|
13926
|
-
type: "uint8"
|
|
13927
|
-
},
|
|
13928
|
-
{
|
|
13929
|
-
name: "safeTxGas",
|
|
13930
|
-
type: "uint256"
|
|
13931
|
-
},
|
|
13932
|
-
{
|
|
13933
|
-
name: "baseGas",
|
|
13934
|
-
type: "uint256"
|
|
13935
|
-
},
|
|
13936
|
-
{
|
|
13937
|
-
name: "gasPrice",
|
|
13938
|
-
type: "uint256"
|
|
13939
|
-
},
|
|
13940
|
-
{
|
|
13941
|
-
name: "gasToken",
|
|
13942
|
-
type: "address"
|
|
13943
|
-
},
|
|
13944
|
-
{
|
|
13945
|
-
name: "refundReceiver",
|
|
13946
|
-
type: "address"
|
|
13947
|
-
},
|
|
13948
|
-
{
|
|
13949
|
-
name: "signatures",
|
|
13950
|
-
type: "bytes"
|
|
13951
|
-
}
|
|
13952
|
-
],
|
|
13953
|
-
outputs: [{
|
|
13954
|
-
name: "success",
|
|
13955
|
-
type: "bool"
|
|
13956
|
-
}]
|
|
13957
|
-
}];
|
|
13958
|
-
const multiSendAbi = [{
|
|
13959
|
-
type: "function",
|
|
13960
|
-
name: "multiSend",
|
|
13961
|
-
stateMutability: "payable",
|
|
13962
|
-
inputs: [{
|
|
13963
|
-
name: "transactions",
|
|
13964
|
-
type: "bytes"
|
|
13965
|
-
}],
|
|
13966
|
-
outputs: []
|
|
13967
|
-
}];
|
|
13968
14421
|
const rolesExecTransactionWithRoleVerificationAbi = [{
|
|
13969
14422
|
type: "function",
|
|
13970
14423
|
name: "execTransactionWithRole",
|
|
@@ -14005,9 +14458,7 @@ const rolesExecTransactionWithRoleVerificationAbi = [{
|
|
|
14005
14458
|
inputs: []
|
|
14006
14459
|
}];
|
|
14007
14460
|
const DEFAULT_RECEIPT_TIMEOUT_MS = 12e4;
|
|
14008
|
-
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
14009
14461
|
const SAFE_OPERATION_CALL = 0;
|
|
14010
|
-
const SAFE_OPERATION_DELEGATECALL = 1;
|
|
14011
14462
|
const ASSIGN_ROLES_PERMISSION = "zodiac.roles.assignRoles";
|
|
14012
14463
|
var LiveOrgDeploymentAdapter = class {
|
|
14013
14464
|
#convex;
|
|
@@ -14188,7 +14639,7 @@ var LiveOrgDeploymentAdapter = class {
|
|
|
14188
14639
|
});
|
|
14189
14640
|
const [deployModuleCall, ...orgSafeCalls] = deployment.calls;
|
|
14190
14641
|
if (deployModuleCall === void 0) throw Errors.providerError("permissionless-org-roles-deployment", "deployRoles", "Zodiac Roles deployment builder returned no calls");
|
|
14191
|
-
const calls = [deployModuleCall,
|
|
14642
|
+
const calls = [deployModuleCall, buildSafeMultiSendExecTransactionCall({
|
|
14192
14643
|
safeAddress: toViemHexAddress(wire.safeAddress),
|
|
14193
14644
|
ownerAddress: toViemHexAddress(wire.ownerPersonalSafeAddress),
|
|
14194
14645
|
calls: orgSafeCalls
|
|
@@ -14382,7 +14833,7 @@ async function isContractDeployed(publicClient, address) {
|
|
|
14382
14833
|
return code !== void 0 && code !== "0x";
|
|
14383
14834
|
}
|
|
14384
14835
|
function wireToOrgView(wire, treasury) {
|
|
14385
|
-
return brandOrgView(wire, treasury);
|
|
14836
|
+
return brandOrgView(wire, treasury, "Owner");
|
|
14386
14837
|
}
|
|
14387
14838
|
function deriveLiveSpendAuthority(input) {
|
|
14388
14839
|
if (input.org === null) return inactiveSpendAuthority();
|
|
@@ -14411,9 +14862,9 @@ function spendAuthorityFromRole(role, roleLabel) {
|
|
|
14411
14862
|
activeMember: true,
|
|
14412
14863
|
subAccountBalanceRaw: "100000000000",
|
|
14413
14864
|
recipients: spend?.toRecipients ?? "anyone",
|
|
14414
|
-
subAccounts: subAccountScope ===
|
|
14865
|
+
subAccounts: subAccountScope === "all" ? { scope: "all" } : {
|
|
14415
14866
|
scope: "only",
|
|
14416
|
-
subAccountIds: subAccountScope
|
|
14867
|
+
subAccountIds: subAccountScope?.map(toSubAccountId) ?? []
|
|
14417
14868
|
},
|
|
14418
14869
|
...spend?.perTx === void 0 ? {} : { perTxCapRaw: spend.perTx.value },
|
|
14419
14870
|
...spend?.perDay === void 0 ? {} : { perDayCapRaw: spend.perDay.value },
|
|
@@ -14457,51 +14908,6 @@ async function verifyOrgRoleRevokedOnChain(input) {
|
|
|
14457
14908
|
}
|
|
14458
14909
|
throw Errors.providerError("permissionless-org-roles", "verifyRevoke", "revoked member can still execute its former Zodiac role");
|
|
14459
14910
|
}
|
|
14460
|
-
function buildOrgSafeExecTransactionCall(input) {
|
|
14461
|
-
const data = encodeFunctionData({
|
|
14462
|
-
abi: multiSendAbi,
|
|
14463
|
-
functionName: "multiSend",
|
|
14464
|
-
args: [concat(input.calls.map(encodeMultiSendCallTransaction))]
|
|
14465
|
-
});
|
|
14466
|
-
return {
|
|
14467
|
-
to: input.safeAddress,
|
|
14468
|
-
data: encodeFunctionData({
|
|
14469
|
-
abi: safeExecTransactionAbi,
|
|
14470
|
-
functionName: "execTransaction",
|
|
14471
|
-
args: [
|
|
14472
|
-
MULTI_SEND,
|
|
14473
|
-
0n,
|
|
14474
|
-
data,
|
|
14475
|
-
SAFE_OPERATION_DELEGATECALL,
|
|
14476
|
-
0n,
|
|
14477
|
-
0n,
|
|
14478
|
-
0n,
|
|
14479
|
-
ZERO_ADDRESS,
|
|
14480
|
-
ZERO_ADDRESS,
|
|
14481
|
-
prevalidatedSafeSignature(input.ownerAddress)
|
|
14482
|
-
]
|
|
14483
|
-
}),
|
|
14484
|
-
value: 0n
|
|
14485
|
-
};
|
|
14486
|
-
}
|
|
14487
|
-
function encodeMultiSendCallTransaction(call) {
|
|
14488
|
-
return encodePacked([
|
|
14489
|
-
"uint8",
|
|
14490
|
-
"address",
|
|
14491
|
-
"uint256",
|
|
14492
|
-
"uint256",
|
|
14493
|
-
"bytes"
|
|
14494
|
-
], [
|
|
14495
|
-
SAFE_OPERATION_CALL,
|
|
14496
|
-
call.to,
|
|
14497
|
-
call.value,
|
|
14498
|
-
BigInt((call.data.length - 2) / 2),
|
|
14499
|
-
call.data
|
|
14500
|
-
]);
|
|
14501
|
-
}
|
|
14502
|
-
function prevalidatedSafeSignature(ownerAddress) {
|
|
14503
|
-
return `${padHex(ownerAddress, { size: 32 })}${"0".repeat(64)}01`;
|
|
14504
|
-
}
|
|
14505
14911
|
function requireActiveRole(roles, label) {
|
|
14506
14912
|
const role = roles.find((candidate) => candidate.status === "active" && candidate.label === label);
|
|
14507
14913
|
if (role === void 0) throw Errors.invalidInput("role", `active org role not found: ${label}`);
|
|
@@ -14770,28 +15176,36 @@ async function buildSponsoredSafeUserOp(input) {
|
|
|
14770
15176
|
};
|
|
14771
15177
|
return {
|
|
14772
15178
|
userOp,
|
|
14773
|
-
digest:
|
|
14774
|
-
userOp
|
|
14775
|
-
sender: userOp.sender,
|
|
14776
|
-
nonce,
|
|
14777
|
-
...userOp.factory === void 0 ? {} : { factory: userOp.factory },
|
|
14778
|
-
...userOp.factoryData === void 0 ? {} : { factoryData: userOp.factoryData },
|
|
14779
|
-
callData: userOp.callData,
|
|
14780
|
-
callGasLimit: rpcQuantityToBigInt(userOp.callGasLimit, "callGasLimit"),
|
|
14781
|
-
verificationGasLimit: rpcQuantityToBigInt(userOp.verificationGasLimit, "verificationGasLimit"),
|
|
14782
|
-
preVerificationGas: rpcQuantityToBigInt(userOp.preVerificationGas, "preVerificationGas"),
|
|
14783
|
-
maxFeePerGas: rpcQuantityToBigInt(userOp.maxFeePerGas, "maxFeePerGas"),
|
|
14784
|
-
maxPriorityFeePerGas: rpcQuantityToBigInt(userOp.maxPriorityFeePerGas, "maxPriorityFeePerGas"),
|
|
14785
|
-
paymaster: userOp.paymaster,
|
|
14786
|
-
...userOp.paymasterVerificationGasLimit === void 0 ? {} : { paymasterVerificationGasLimit: rpcQuantityToBigInt(userOp.paymasterVerificationGasLimit, "paymasterVerificationGasLimit") },
|
|
14787
|
-
...userOp.paymasterPostOpGasLimit === void 0 ? {} : { paymasterPostOpGasLimit: rpcQuantityToBigInt(userOp.paymasterPostOpGasLimit, "paymasterPostOpGasLimit") },
|
|
14788
|
-
paymasterData: userOp.paymasterData
|
|
14789
|
-
},
|
|
15179
|
+
digest: deploymentUserOpDigest({
|
|
15180
|
+
userOp,
|
|
14790
15181
|
chainId
|
|
14791
15182
|
}),
|
|
14792
15183
|
safeAddress: sender
|
|
14793
15184
|
};
|
|
14794
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
|
+
}
|
|
14795
15209
|
//#endregion
|
|
14796
15210
|
//#region src/settlement-port.ts
|
|
14797
15211
|
const ADDRESS_RE$1 = /^0x[0-9a-fA-F]{40}$/;
|
|
@@ -15507,8 +15921,8 @@ async function executeCommitmentRedirect(input) {
|
|
|
15507
15921
|
*/
|
|
15508
15922
|
async function fetchCommitmentCreatedIdFromLogs(input) {
|
|
15509
15923
|
const { keccak256, toBytes } = await import("viem");
|
|
15510
|
-
const { fetchCommitmentCreatedLog } = await import("./alchemy-rpc-
|
|
15511
|
-
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");
|
|
15512
15926
|
const topic0 = keccak256(toBytes("CommitmentCreated(uint256,address,address,address,uint256,uint48,uint48,uint48,bytes32,uint8)"));
|
|
15513
15927
|
const idTopic = (await fetchCommitmentCreatedLog({
|
|
15514
15928
|
chainId: input.chainId,
|