@capxul/sdk 1.2.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { A as OBSERVATION_CONTEXT_HEADER, B as normalizeBindingEmail, C as convexCallErrorFromCapxul, D as bootstrapErrorFromCapxul, E as BootstrapPortTag, F as isSettingUpLifecycle, I as formatTraceparent, L as EXCEPTION_MESSAGE, M as sanitizeObservationContext, N as CAPXUL_FUNCTIONS, O as authClientPortFromPromiseAdapter, P as BootstrapEnvelope, R as captureException, S as ConvexCallPortTag, T as ClockPortTag, U as destination, V as BASE_SEPOLIA_CHAIN_ID, _ as identityErrorFromCapxul, a as redactTelemetryProps, b as markFailureInvocationSnapshot, c as smartAccountErrorFromCapxul, d as fromWei, f as AccountReadPortTag, g as IdentityPortTag, h as wireChainId, j as encodeObservationContextHeader, k as AuthClientPortTag, l as SubAccountPortTag, m as toWei, n as detectAuthCacheAdapter, o as stampTelemetryEnvelope, p as accountReadErrorFromCapxul, r as TelemetryPortTag, s as SmartAccountPortTag, t as assembleCapxulClient, u as subAccountErrorFromCapxul, v as copyInvocationObservation, w as ClockError, x as readInvocationObservation, y as hasFailureInvocationSnapshot, z as captureExceptionSync } from "./create-capxul-client-DVzm78RU.mjs";
2
- import { A as decodeConvexError, C as toJwtToken, D as toRoleKey, E as toPublishableKey, M as EXPECTED_OPERATION_OUTCOMES, N as Errors, O as toSessionToken, P as isCapxulError, S as toEpochSeconds, T as toOrgId, _ as toCountryCode, b as toEmail, d as toAccountId, f as toAddress, g as toChainId, h as toAuthUserId, j as CapxulError, k as toSubAccountId, o as AuthCachePortTag, p as toAllowedOrigin, v as toCurrencyCode, w as toKycTier, x as toEpochMs, y as toDurationMs } from "./InMemoryAuthCacheAdapter-Dr1sEd9y.mjs";
1
+ import { A as encodeObservationContextHeader, B as captureExceptionSync, C as ClockPortTag, D as AuthClientPortTag, E as authClientPortFromPromiseAdapter, F as isSettingUpLifecycle, G as destination, H as normalizeBindingEmail, I as formatTraceparent, L as copyInvocationObservation, M as CAPXUL_FUNCTIONS, N as BootstrapEnvelope, O as version, P as EngineeringTelemetryBootstrapPolicy, R as readInvocationObservation, S as ClockError, T as bootstrapErrorFromCapxul, U as BASE_SEPOLIA_CHAIN_ID, V as CAPXUL_PAYMENTS_V2_ADDRESS, _ as wireChainId, a as observeFailedResult, b as ConvexCallPortTag, c as PostHogTelemetryLayer, d as SmartAccountPortTag, f as smartAccountErrorFromCapxul, g as toWei, h as accountReadErrorFromCapxul, i as observationContextProps, j as sanitizeObservationContext, k as OBSERVATION_CONTEXT_HEADER, l as TelemetryPortTag, m as AccountReadPortTag, n as postHogProductTelemetry, o as postHogFailureObservation, p as fromWei, r as CAPXUL_SDK_EXPECTED_OUTCOME_EVENT, s as detectAuthCacheAdapter, t as assembleCapxulClient, v as IdentityPortTag, w as BootstrapPortTag, x as convexCallErrorFromCapxul, y as identityErrorFromCapxul, z as captureException } from "./create-capxul-client-N36cHqE2.mjs";
2
+ import { A as toSessionToken, C as toEpochMs, D as toOrgId, E as toKycTier, F as isCapxulError, M as CapxulError, O as toPublishableKey, P as Errors, S as toEmail, T as toJwtToken, _ as toAuthUserId, b as toCurrencyCode, h as toAllowedOrigin, j as decodeConvexError, k as toRoleKey, m as toAddress, o as AuthCachePortTag, p as toAccountId, v as toChainId, w as toEpochSeconds, x as toDurationMs, y as toCountryCode } from "./InMemoryAuthCacheAdapter-Rc8tCtml.mjs";
3
3
  import { keccak256, recoverAddress, stringToHex } from "viem";
4
4
  import { Cause, Context, Data, Effect, Exit, Layer, Result, SchemaIssue, SchemaParser, Scope, Tracer } from "effect";
5
5
  import { getFunctionName, makeFunctionReference } from "convex/server";
@@ -304,9 +304,6 @@ async function recoverRawDigestSigner(input) {
304
304
  }
305
305
  }
306
306
  //#endregion
307
- //#region package.json
308
- var version = "1.2.2";
309
- //#endregion
310
307
  //#region ../observability/src/engineering.ts
311
308
  const SAFE_TRACED_HEADER_NAMES = [
312
309
  "content-length",
@@ -346,7 +343,7 @@ const validateEngineeringTelemetryConfig = (config) => {
346
343
  } catch {
347
344
  throw new TypeError("engineering telemetry host must be an absolute HTTPS URL");
348
345
  }
349
- if (url.protocol !== "https:" || url.username.length > 0 || url.password.length > 0 || url.pathname !== "/" || url.search.length > 0 || url.hash.length > 0) throw new TypeError("engineering telemetry host must be a credential-free HTTPS origin");
346
+ if (url.protocol !== "https:" || url.username.length > 0 || url.password.length > 0 || url.pathname !== "/" || url.search.length > 0 || url.hash.length > 0 || !(url.hostname === "posthog.com" || url.hostname.endsWith(".posthog.com"))) throw new TypeError("engineering telemetry host must be a credential-free HTTPS origin");
350
347
  if (!ENGINEERING_CAPXUL_ENVS.has(config.capxulEnv)) throw new TypeError("engineering telemetry capxulEnv is not canonical");
351
348
  if (!ENGINEERING_PRODUCERS.has(config.producer)) throw new TypeError("engineering telemetry producer is not canonical");
352
349
  if (!SAFE_RESOURCE_VALUE.test(config.sdkVersion)) throw new TypeError("engineering telemetry sdkVersion must be a bounded safe value");
@@ -420,10 +417,12 @@ function resolveAuthClientUrl(authBaseUrl, path) {
420
417
  //#endregion
421
418
  //#region src/internal/observation-http.ts
422
419
  /** Resolve one bounded pre-auth snapshot for an outbound SDK HTTP request. */
423
- function observationRequestHeaders(adapter) {
420
+ function observationRequestHeaders(adapter, source) {
424
421
  if (adapter === void 0) return {};
425
422
  try {
426
- const encoded = encodeObservationContextHeader(adapter.resolveContext?.());
423
+ const invocation = readInvocationObservation(source);
424
+ if (invocation !== void 0 && !invocation.active) return {};
425
+ const encoded = encodeObservationContextHeader(invocation === void 0 ? adapter.resolveContext?.() : invocation.context);
427
426
  return encoded === void 0 ? {} : { [OBSERVATION_CONTEXT_HEADER]: encoded };
428
427
  } catch {
429
428
  return {};
@@ -519,7 +518,7 @@ var BetterAuthBrowserAdapter = class {
519
518
  method: "POST",
520
519
  headers: {
521
520
  "Content-Type": "application/json",
522
- ...observationRequestHeaders(this.observation)
521
+ ...observationRequestHeaders(this.observation, input)
523
522
  },
524
523
  body: JSON.stringify({
525
524
  email: input.email,
@@ -937,7 +936,7 @@ var BetterAuthNodeAdapter = class {
937
936
  headers: {
938
937
  "content-type": "application/json",
939
938
  ...this.origin ? { origin: this.origin } : {},
940
- ...observationRequestHeaders(this.observation)
939
+ ...observationRequestHeaders(this.observation, input)
941
940
  },
942
941
  body: JSON.stringify({
943
942
  email: input.email,
@@ -1192,20 +1191,28 @@ var HttpBootstrapAdapter = class {
1192
1191
  if (res.ok) return Effect.tryPromise({
1193
1192
  try: async () => {
1194
1193
  const body = await res.json();
1195
- const decoded = SchemaParser.decodeUnknownResult(BootstrapEnvelope)(body);
1194
+ const state = typeof body === "object" && body !== null && "state" in body && typeof body.state === "object" && body.state !== null ? body.state : void 0;
1195
+ const rawEngineeringTelemetry = state?.engineeringTelemetry;
1196
+ const baseBody = state === void 0 || rawEngineeringTelemetry === void 0 ? body : {
1197
+ ...body,
1198
+ state: Object.fromEntries(Object.entries(state).filter(([key]) => key !== "engineeringTelemetry"))
1199
+ };
1200
+ const decoded = SchemaParser.decodeUnknownResult(BootstrapEnvelope)(baseBody);
1196
1201
  if (Result.isFailure(decoded)) throw Errors.invalidInput("bootstrapEnvelope", SchemaIssue.makeFormatterDefault()(decoded.failure));
1197
- const { state } = decoded.success;
1202
+ const { state: decodedState } = decoded.success;
1203
+ const decodedEngineeringTelemetry = rawEngineeringTelemetry === void 0 ? void 0 : SchemaParser.decodeUnknownResult(EngineeringTelemetryBootstrapPolicy)(rawEngineeringTelemetry, { onExcessProperty: "error" });
1198
1204
  return {
1199
- applicationId: state.applicationId,
1200
- chainId: state.chainId,
1201
- sessionToken: state.sessionToken,
1202
- issuedAt: state.issuedAt,
1203
- expiresIn: state.expiresIn,
1204
- authBaseUrl: normalizeRuntimeUrl("authBaseUrl", state.authBaseUrl),
1205
- convexUrl: normalizeRuntimeUrl("convexUrl", state.convexUrl),
1206
- siteBaseUrl: normalizeRuntimeUrl("siteBaseUrl", state.siteBaseUrl),
1207
- openfortPublishableKey: state.openfortPublishableKey,
1208
- shieldPublishableKey: state.shieldPublishableKey
1205
+ applicationId: decodedState.applicationId,
1206
+ chainId: decodedState.chainId,
1207
+ sessionToken: decodedState.sessionToken,
1208
+ issuedAt: decodedState.issuedAt,
1209
+ expiresIn: decodedState.expiresIn,
1210
+ authBaseUrl: normalizeRuntimeUrl("authBaseUrl", decodedState.authBaseUrl),
1211
+ convexUrl: normalizeRuntimeUrl("convexUrl", decodedState.convexUrl),
1212
+ siteBaseUrl: normalizeRuntimeUrl("siteBaseUrl", decodedState.siteBaseUrl),
1213
+ openfortPublishableKey: decodedState.openfortPublishableKey,
1214
+ shieldPublishableKey: decodedState.shieldPublishableKey,
1215
+ ...decodedEngineeringTelemetry !== void 0 && Result.isSuccess(decodedEngineeringTelemetry) ? { engineeringTelemetry: decodedEngineeringTelemetry.success } : {}
1209
1216
  };
1210
1217
  },
1211
1218
  catch: (cause) => {
@@ -1257,7 +1264,6 @@ function SystemClockLayer() {
1257
1264
  //#region src/adapters/convex-call/ConvexCallAdapter.ts
1258
1265
  /** Exact floor-first allowlist; every additional handler must migrate its validator first. */
1259
1266
  const OBSERVED_CONVEX_ACTIONS = new Set([
1260
- "subAccount/actions:transfer",
1261
1267
  "smartAccount/actions:claim",
1262
1268
  "org/actions:prepareFounderAccount",
1263
1269
  "org/actions:prepareBootstrap",
@@ -1458,7 +1464,7 @@ function identityErrorFromUnknown(operation, cause) {
1458
1464
  }
1459
1465
  //#endregion
1460
1466
  //#region src/adapters/account-read/ConvexAccountAdapter.ts
1461
- const DEFAULT_FUNCTIONS$4 = {
1467
+ const DEFAULT_FUNCTIONS$3 = {
1462
1468
  readBalance: makeFunctionReference(CAPXUL_FUNCTIONS["account/actions"].readBalance),
1463
1469
  faucetMint: makeFunctionReference(CAPXUL_FUNCTIONS["account/actions"].faucetMint)
1464
1470
  };
@@ -1467,7 +1473,7 @@ var ConvexAccountAdapter = class {
1467
1473
  #fns;
1468
1474
  constructor(deps) {
1469
1475
  this.#convex = deps.convex;
1470
- this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$4;
1476
+ this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$3;
1471
1477
  }
1472
1478
  readBalance(input) {
1473
1479
  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.catchDefect((cause) => Effect.fail(accountReadErrorFromUnknown("readBalance", cause))));
@@ -1506,92 +1512,6 @@ function accountReadErrorFromUnknown(operation, cause) {
1506
1512
  return accountReadErrorFromCapxul(operation, Errors.providerError("convex", operation, cause), cause);
1507
1513
  }
1508
1514
  //#endregion
1509
- //#region src/adapters/sub-account/ConvexSubAccountAdapter.ts
1510
- const DEFAULT_FUNCTIONS$3 = {
1511
- create: makeFunctionReference(CAPXUL_FUNCTIONS["subAccount/mutations"].create),
1512
- get: makeFunctionReference(CAPXUL_FUNCTIONS["subAccount/queries"].get),
1513
- list: makeFunctionReference(CAPXUL_FUNCTIONS["subAccount/queries"].list),
1514
- rename: makeFunctionReference(CAPXUL_FUNCTIONS["subAccount/mutations"].rename),
1515
- remove: makeFunctionReference(CAPXUL_FUNCTIONS["subAccount/mutations"].remove),
1516
- transfer: makeFunctionReference(CAPXUL_FUNCTIONS["subAccount/actions"].transfer)
1517
- };
1518
- var ConvexSubAccountAdapter = class {
1519
- #convex;
1520
- #fns;
1521
- #chainId;
1522
- constructor(deps) {
1523
- this.#convex = deps.convex;
1524
- this.#chainId = deps.chainId;
1525
- this.#fns = deps.functions ?? DEFAULT_FUNCTIONS$3;
1526
- }
1527
- create(input) {
1528
- return this.#runMutation("create", this.#fns.create, {
1529
- accountId: input.accountId,
1530
- name: input.name
1531
- });
1532
- }
1533
- get(input) {
1534
- return this.#runQuery("get", this.#fns.get, { subAccountId: input.subAccountId }, (wire) => wire === null ? null : brandSubAccount(wire));
1535
- }
1536
- list(input) {
1537
- return this.#runQuery("list", this.#fns.list, { accountId: input.accountId }, (wires) => wires.map((wire) => brandSubAccount(wire)));
1538
- }
1539
- rename(input) {
1540
- return this.#runMutation("rename", this.#fns.rename, {
1541
- subAccountId: input.subAccountId,
1542
- name: input.name
1543
- });
1544
- }
1545
- delete(input) {
1546
- const operation = "delete";
1547
- return this.#convex.mutation(this.#fns.remove, { subAccountId: input.subAccountId }).pipe(Effect.mapError((error) => subAccountErrorFromCapxul(operation, error.publicError, error)), Effect.asVoid, Effect.catchDefect((cause) => Effect.fail(subAccountErrorFromUnknown(operation, cause))));
1548
- }
1549
- transfer(input) {
1550
- const operation = "transfer";
1551
- return Effect.suspend(() => {
1552
- const rawAmount = toWei(input.amount);
1553
- return this.#convex.action(this.#fns.transfer, copyInvocationObservation(input, {
1554
- chainId: this.#chainId,
1555
- from: input.from,
1556
- to: input.to,
1557
- rawAmount
1558
- }));
1559
- }).pipe(Effect.mapError((error) => subAccountErrorFromCapxul(operation, error.publicError, error)), Effect.map((wire) => brandTransferResult(wire)), Effect.catchDefect((cause) => Effect.fail(subAccountErrorFromUnknown(operation, cause))));
1560
- }
1561
- #runMutation(operation, ref, args) {
1562
- return this.#convex.mutation(ref, args).pipe(Effect.mapError((error) => subAccountErrorFromCapxul(operation, error.publicError, error)), Effect.map((wire) => brandSubAccount(wire)), Effect.catchDefect((cause) => Effect.fail(subAccountErrorFromUnknown(operation, cause))));
1563
- }
1564
- #runQuery(operation, ref, args, map) {
1565
- return this.#convex.query(ref, args).pipe(Effect.mapError((error) => subAccountErrorFromCapxul(operation, error.publicError, error)), Effect.map(map), Effect.catchDefect((cause) => Effect.fail(subAccountErrorFromUnknown(operation, cause))));
1566
- }
1567
- };
1568
- function ConvexSubAccountLayer(chainId) {
1569
- return Layer.effect(SubAccountPortTag, Effect.map(ConvexCallPortTag, (convex) => new ConvexSubAccountAdapter({
1570
- convex,
1571
- chainId
1572
- })));
1573
- }
1574
- function brandTransferResult(wire) {
1575
- return {
1576
- available: fromWei(wire.availableRaw, wire.decimals, wire.currency),
1577
- from: wire.from === null ? null : brandSubAccount(wire.from),
1578
- to: wire.to === null ? null : brandSubAccount(wire.to)
1579
- };
1580
- }
1581
- function brandSubAccount(wire) {
1582
- return {
1583
- id: toSubAccountId(wire.subAccountId),
1584
- accountId: toAccountId(wire.accountId),
1585
- name: wire.name,
1586
- balance: fromWei(wire.rawBalance, wire.decimals, wire.currency),
1587
- createdAt: toEpochMs(wire.createdAt)
1588
- };
1589
- }
1590
- function subAccountErrorFromUnknown(operation, cause) {
1591
- if (cause instanceof CapxulError) return subAccountErrorFromCapxul(operation, cause);
1592
- return subAccountErrorFromCapxul(operation, Errors.providerError("convex", operation, cause), cause);
1593
- }
1594
- //#endregion
1595
1515
  //#region src/adapters/smart-account/ConvexSmartAccountAdapter.ts
1596
1516
  const DEFAULT_FUNCTIONS$2 = {
1597
1517
  loadByAuthUserId: makeFunctionReference(CAPXUL_FUNCTIONS["smartAccount/queries"].loadByAuthUserId),
@@ -1631,7 +1551,6 @@ var ConvexSmartAccountAdapter = class {
1631
1551
  return this.#convex.action(this.#fns.confirmDeployment, {
1632
1552
  chainId: wireChainId(input.chainId),
1633
1553
  safeAddress: input.safeAddress,
1634
- ...input.telemetryRunId === void 0 ? {} : { telemetryRunId: input.telemetryRunId },
1635
1554
  evidence
1636
1555
  }).pipe(Effect.mapError((error) => smartAccountErrorFromCapxul("confirmDeployment", error.publicError, error)), Effect.flatMap((row) => Effect.try({
1637
1556
  try: () => brandProvisionedSmartAccount(input.authUserId, row),
@@ -1641,8 +1560,7 @@ var ConvexSmartAccountAdapter = class {
1641
1560
  claim(input) {
1642
1561
  return this.#convex.action(this.#fns.claim, copyInvocationObservation(input, {
1643
1562
  chainId: wireChainId(input.chainId),
1644
- signerAddress: input.signerAddress,
1645
- ...input.telemetryRunId === void 0 ? {} : { telemetryRunId: input.telemetryRunId }
1563
+ signerAddress: input.signerAddress
1646
1564
  })).pipe(Effect.mapError((error) => smartAccountErrorFromCapxul("claim", error.publicError, error)), Effect.flatMap((row) => Effect.try({
1647
1565
  try: () => brandProvisionedSmartAccount(input.authUserId, row),
1648
1566
  catch: (cause) => smartAccountErrorFromUnknown("claim", cause)
@@ -1690,8 +1608,6 @@ function orgErrorFromCapxul(operation, error, cause = error) {
1690
1608
  });
1691
1609
  }
1692
1610
  var OrgPortTag = class extends Context.Service()("@capxul/sdk/ports/OrgPort") {};
1693
- Context.Service()("@capxul/sdk/ports/OrgRolesDeploymentPort");
1694
- Context.Service()("@capxul/sdk/ports/OrgSpendPort");
1695
1611
  //#endregion
1696
1612
  //#region src/adapters/org/parse.ts
1697
1613
  /**
@@ -1763,7 +1679,6 @@ function parseRoleDefinition(json) {
1763
1679
  ...raw.spend.perDay === void 0 ? {} : { perDay: parseRoleMoney(raw.spend.perDay, "perDay") },
1764
1680
  ...raw.spend.toRecipients === void 0 ? {} : { toRecipients: parseRoleRecipients(raw.spend.toRecipients) }
1765
1681
  } },
1766
- ...raw.subAccounts === void 0 ? {} : { subAccounts: parseRoleSubAccounts(raw.subAccounts) },
1767
1682
  ...typeof raw.canManageMembers === "boolean" ? { canManageMembers: raw.canManageMembers } : {},
1768
1683
  ...typeof raw.canManageRoles === "boolean" ? { canManageRoles: raw.canManageRoles } : {}
1769
1684
  };
@@ -1784,14 +1699,6 @@ function parseRoleRecipients(raw) {
1784
1699
  return toAddress(recipient);
1785
1700
  });
1786
1701
  }
1787
- function parseRoleSubAccounts(raw) {
1788
- if (raw.scope === "all") return { scope: "all" };
1789
- if (!Array.isArray(raw.scope)) throw new Error("Invalid role definition: subAccounts.scope must be \"all\" or an array");
1790
- return { scope: raw.scope.map((subAccountId) => {
1791
- if (typeof subAccountId !== "string") throw new Error("Invalid role definition: subAccounts.scope must be \"all\" or an array");
1792
- return toSubAccountId(subAccountId);
1793
- }) };
1794
- }
1795
1702
  /** Strip the `org_` prefix + non-alphanumerics so the body re-seeds `account_`. */
1796
1703
  function orgIdBody(orgId) {
1797
1704
  const underscore = orgId.indexOf("_");
@@ -2154,90 +2061,6 @@ function fail(error) {
2154
2061
  };
2155
2062
  }
2156
2063
  //#endregion
2157
- //#region src/adapters/telemetry/PostHogTelemetryAdapter.ts
2158
- var PostHogTelemetryAdapter = class {
2159
- #capture;
2160
- #identify;
2161
- #group;
2162
- #reset;
2163
- constructor(deps) {
2164
- this.#capture = deps.capture;
2165
- this.#identify = deps.identify ?? (() => void 0);
2166
- this.#group = deps.group ?? (() => void 0);
2167
- this.#reset = deps.reset ?? (() => void 0);
2168
- }
2169
- emit(event) {
2170
- return this.#run(() => this.#capture(event.name, redactTelemetryProps(event.name, cloneProps(event.props))), "emit", event.name);
2171
- }
2172
- identify(input) {
2173
- return this.#run(() => this.#identify(cloneIdentifyInput(input)), "identify");
2174
- }
2175
- group(input) {
2176
- return this.#run(() => this.#group(cloneGroupInput(input)), "group");
2177
- }
2178
- reset() {
2179
- return this.#run(() => this.#reset(), "reset");
2180
- }
2181
- #run(operation, operationName, eventName) {
2182
- const diagnose = Effect.logWarning("product.telemetry.transport.dropped").pipe(Effect.annotateLogs({
2183
- operation: operationName,
2184
- ...eventName === void 0 ? {} : { product_event: eventName }
2185
- }), Effect.catchCause(() => Effect.void));
2186
- return Effect.suspend(() => {
2187
- let pending;
2188
- try {
2189
- pending = operation();
2190
- } catch {
2191
- return diagnose;
2192
- }
2193
- if (pending === void 0) return Effect.void;
2194
- const transport = Effect.tryPromise({
2195
- try: () => pending,
2196
- catch: () => void 0
2197
- }).pipe(Effect.catch(() => diagnose));
2198
- return Effect.forkDetach(transport, { startImmediately: true }).pipe(Effect.asVoid);
2199
- });
2200
- }
2201
- };
2202
- function PostHogTelemetryLayer(deps) {
2203
- return Layer.succeed(TelemetryPortTag, new PostHogTelemetryAdapter(deps));
2204
- }
2205
- function cloneIdentifyInput(input) {
2206
- const traits = input.traits === void 0 ? void 0 : cloneProps(input.traits);
2207
- const properties = input.properties === void 0 ? void 0 : cloneProps(input.properties);
2208
- return {
2209
- distinctId: input.distinctId,
2210
- ...input.anonDistinctId === void 0 ? {} : { anonDistinctId: input.anonDistinctId },
2211
- ...traits === void 0 ? {} : { traits },
2212
- ...properties === void 0 ? {} : { properties }
2213
- };
2214
- }
2215
- function cloneGroupInput(input) {
2216
- const properties = input.properties === void 0 ? void 0 : cloneProps(input.properties);
2217
- return properties === void 0 ? {
2218
- groupType: input.groupType,
2219
- groupKey: input.groupKey
2220
- } : {
2221
- groupType: input.groupType,
2222
- groupKey: input.groupKey,
2223
- properties
2224
- };
2225
- }
2226
- function cloneProps(props) {
2227
- if (props === void 0) return void 0;
2228
- const cloned = {};
2229
- for (const [key, value] of Object.entries(props)) cloned[key] = cloneTelemetryValue(value);
2230
- return cloned;
2231
- }
2232
- function cloneTelemetryValue(value) {
2233
- if (Array.isArray(value)) return value.map(cloneTelemetryValue);
2234
- if (value === null || typeof value !== "object") return value;
2235
- if (Object.getPrototypeOf(value) !== Object.prototype) return value;
2236
- const cloned = {};
2237
- for (const [key, nested] of Object.entries(value)) cloned[key] = cloneTelemetryValue(nested);
2238
- return cloned;
2239
- }
2240
- //#endregion
2241
2064
  //#region src/adapters/diagnostic/ConsoleDiagnosticAdapter.ts
2242
2065
  const DEFAULT_ACCOUNT_SETUP_LOG_PREFIX = "[capxul:account-setup]";
2243
2066
  var ConsoleDiagnosticAdapter = class {
@@ -2497,220 +2320,73 @@ function normalizeBetterAuthBaseUrl(raw) {
2497
2320
  return trimmed.endsWith("/api/auth") ? trimmed : `${trimmed}/api/auth`;
2498
2321
  }
2499
2322
  //#endregion
2500
- //#region src/observation.ts
2501
- const SDK_VERSION$1 = version;
2502
- /** Stable PostHog event used for typed failures that are expected product outcomes. */
2503
- const CAPXUL_SDK_EXPECTED_OUTCOME_EVENT = "capxul_sdk_expected_outcome";
2504
- /**
2505
- * Adapt the host's already-initialized PostHog-like client. This function does
2506
- * not import, initialize, configure, or own PostHog.
2507
- */
2508
- function fromPostHog(client, options = {}) {
2509
- const prepare = (failure) => {
2510
- if (!isEnabled(options.enabled)) return;
2511
- if (client === null || client === void 0) return;
2512
- const safeFailure = sanitizeFailureObservation(failure);
2513
- return [safeFailure, postHogProperties(safeFailure, hasFailureInvocationSnapshot(failure) ? void 0 : resolveContext(options.context))];
2514
- };
2515
- const captureOperationFailure = (failure) => {
2516
- const prepared = prepare(failure);
2517
- if (prepared === void 0 || client === null || client === void 0) return;
2518
- const [safeFailure, properties] = prepared;
2519
- if (classifyOperationOutcome(safeFailure.errorKind) === "expected") {
2520
- if (typeof client.capture !== "function") return;
2521
- deliver(() => client.capture(CAPXUL_SDK_EXPECTED_OUTCOME_EVENT, {
2522
- ...properties,
2523
- outcome_class: "expected"
2524
- }));
2525
- return;
2323
+ //#region src/host-observability.ts
2324
+ const HOST_INVOCATION = Symbol("capxul.host-observability-invocation");
2325
+ /** Build the SDK's one host module around an already-initialized PostHog client. */
2326
+ function postHogObservability(client, options = {}) {
2327
+ const inactive = Object.freeze({
2328
+ active: false,
2329
+ contextProps: Object.freeze({})
2330
+ });
2331
+ const snapshot = () => {
2332
+ if (client === null || client === void 0) return inactive;
2333
+ try {
2334
+ if (!(typeof options.enabled === "function" ? options.enabled() : options.enabled ?? true)) return inactive;
2335
+ const sanitized = sanitizeObservationContext(typeof options.context === "function" ? options.context() : options.context);
2336
+ const context = sanitized === void 0 ? void 0 : Object.freeze({ ...sanitized });
2337
+ return Object.freeze({
2338
+ active: true,
2339
+ ...context === void 0 ? {} : { context },
2340
+ contextProps: Object.freeze(observationContextProps(context))
2341
+ });
2342
+ } catch {
2343
+ return inactive;
2526
2344
  }
2527
- deliver(() => client.capture("$exception", postHogExceptionProperties(safeFailure, properties)));
2528
- };
2529
- const captureException = (failure) => {
2530
- const prepared = prepare(failure);
2531
- if (prepared === void 0 || client === null || client === void 0) return;
2532
- const [safeFailure, properties] = prepared;
2533
- deliver(() => client.capture("$exception", postHogExceptionProperties(safeFailure, properties)));
2534
2345
  };
2535
- return {
2536
- resolveContext: () => {
2537
- if (!isEnabled(options.enabled) || client === null || client === void 0) return void 0;
2538
- return resolveRawContext(options.context) ?? {};
2539
- },
2540
- captureOperationFailure,
2541
- captureException
2346
+ const policy = {
2347
+ client,
2348
+ capxulEnv: options.capxulEnv ?? "unknown",
2349
+ snapshot,
2350
+ deliver: (capture) => {
2351
+ try {
2352
+ const delivery = capture();
2353
+ if (isPromiseLike(delivery)) Promise.resolve(delivery).catch(() => void 0);
2354
+ } catch {}
2355
+ }
2542
2356
  };
2543
- }
2544
- function classifyOperationOutcome(kind) {
2545
- return EXPECTED_OPERATION_OUTCOMES.has(kind) ? "expected" : "unexpected";
2546
- }
2547
- function deliver(capture) {
2548
- try {
2549
- ignoreDeliveryFailure(capture());
2550
- } catch {}
2551
- }
2552
- /** @internal Reports a factory-level typed failure without changing its identity. */
2553
- function observeFailedResult(result, adapter, operation) {
2554
- if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterContext(adapter));
2555
- return result;
2556
- }
2557
- function report(adapter, kind, operation, cause, invocationContext) {
2558
- const operationName = normalizeOperation(operation);
2559
- const kindName = normalizeErrorKind(errorKind(cause));
2560
- const context = sanitizeObservationContext({
2561
- ...invocationContext,
2562
- ...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
2563
- });
2564
- const failure = markFailureInvocationSnapshot({
2565
- exception: syntheticException(operationName, kindName),
2566
- sdkVersion: SDK_VERSION$1,
2567
- operation: operationName,
2568
- errorKind: kindName,
2569
- ...context === void 0 ? {} : { context }
2570
- });
2571
- try {
2572
- ignoreDeliveryFailure(kind === "operation" ? adapter.captureOperationFailure(failure) : adapter.captureException(failure));
2573
- } catch {}
2574
- }
2575
- function resolveAdapterContext(adapter) {
2576
- try {
2577
- return adapter.resolveContext?.();
2578
- } catch {
2579
- return;
2580
- }
2581
- }
2582
- function ignoreDeliveryFailure(delivery) {
2583
- if (!isPromiseLike(delivery)) return;
2584
- try {
2585
- Promise.resolve(delivery).catch(() => void 0);
2586
- } catch {}
2587
- }
2588
- /**
2589
- * Map an ALREADY-sanitized observation context to the snake_case PostHog
2590
- * property keys. Shared by the failure boundary here and the host
2591
- * success-telemetry seam (`telemetry/from-posthog.ts`) so both attach identical
2592
- * correlation fields from one definition.
2593
- */
2594
- function observationContextProps(context) {
2595
- const props = {};
2596
- if (context?.application !== void 0) props.application = context.application;
2597
- if (context?.release !== void 0) props.release = context.release;
2598
- if (context?.sessionId !== void 0) props.session_id = context.sessionId;
2599
- if (context?.organizationId !== void 0) props.organization_id = context.organizationId;
2600
- if (context?.journeyId !== void 0) props.journey_id = context.journeyId;
2601
- if (context?.correlationId !== void 0) props.correlation_id = context.correlationId;
2602
- if (context?.anonymousId !== void 0) props.anonymous_id = context.anonymousId;
2603
- return props;
2604
- }
2605
- function postHogProperties(failure, context) {
2606
- const merged = sanitizeObservationContext({
2607
- ...context,
2608
- ...failure.context
2609
- });
2610
- return {
2611
- sdk_version: failure.sdkVersion,
2612
- operation: failure.operation,
2613
- error_kind: failure.errorKind,
2614
- handled: true,
2615
- ...observationContextProps(merged)
2357
+ const module = {
2358
+ failures: postHogFailureObservation(policy),
2359
+ product: postHogProductTelemetry(policy)
2616
2360
  };
2617
- }
2618
- function postHogExceptionProperties(failure, properties) {
2619
- const filename = `capxul-sdk-observation://boundary/${failure.operation}`;
2620
- return {
2621
- ...properties,
2622
- $exception_type: failure.errorKind,
2623
- $exception_message: EXCEPTION_MESSAGE,
2624
- $exception_level: "error",
2625
- $exception_list: [{
2626
- type: failure.errorKind,
2627
- value: EXCEPTION_MESSAGE,
2628
- mechanism: {
2629
- type: "capxul_sdk_boundary",
2630
- handled: true,
2631
- synthetic: true
2361
+ Object.defineProperty(module, HOST_INVOCATION, {
2362
+ enumerable: false,
2363
+ value: {
2364
+ bind: () => {
2365
+ const invocation = snapshot();
2366
+ return {
2367
+ failures: postHogFailureObservation(policy, invocation),
2368
+ product: postHogProductTelemetry(policy, invocation)
2369
+ };
2632
2370
  },
2633
- stacktrace: {
2634
- type: "raw",
2635
- frames: [{
2636
- platform: "javascript",
2637
- filename,
2638
- function: `CapxulSdkBoundary.${failure.operation}`,
2639
- lineno: 1,
2640
- colno: 1,
2641
- in_app: true
2642
- }]
2643
- }
2644
- }]
2645
- };
2646
- }
2647
- function resolveContext(context) {
2648
- return sanitizeObservationContext(resolveRawContext(context));
2649
- }
2650
- /** Resolve the host context closure without sanitizing — the call-start snapshot. */
2651
- function resolveRawContext(context) {
2652
- try {
2653
- return typeof context === "function" ? context() : context;
2654
- } catch {
2655
- return;
2656
- }
2657
- }
2658
- function isEnabled(enabled) {
2659
- try {
2660
- return typeof enabled === "function" ? enabled() : enabled ?? true;
2661
- } catch {
2662
- return false;
2663
- }
2664
- }
2665
- function errorKind(cause) {
2666
- try {
2667
- if (isCapxulError(cause)) return normalizeErrorKind(cause.code);
2668
- if (cause instanceof Error) return normalizeErrorKind(cause.name);
2669
- return "UnknownFailure";
2670
- } catch {
2671
- return "Error";
2672
- }
2673
- }
2674
- function sanitizeFailureObservation(failure) {
2675
- const operation = normalizeOperation(failure.operation);
2676
- const kind = normalizeErrorKind(failure.errorKind);
2677
- const context = sanitizeObservationContext(failure.context);
2678
- return {
2679
- exception: syntheticException(operation, kind),
2680
- sdkVersion: normalizeSdkVersion(failure.sdkVersion),
2681
- operation,
2682
- errorKind: kind,
2683
- ...context === void 0 ? {} : { context }
2371
+ snapshot
2372
+ }
2373
+ });
2374
+ return module;
2375
+ }
2376
+ /** @internal Bind both projections to one call-start decision/context snapshot. */
2377
+ function bindHostObservabilityInvocation(observability) {
2378
+ return observability?.[HOST_INVOCATION]?.bind() ?? observability;
2379
+ }
2380
+ /** @internal Read one call-start snapshot for actor/transition carriage. */
2381
+ function snapshotHostObservability(observability) {
2382
+ const snapshot = observability?.[HOST_INVOCATION]?.snapshot();
2383
+ return snapshot === void 0 ? void 0 : {
2384
+ active: snapshot.active,
2385
+ ...snapshot.context === void 0 ? {} : { context: snapshot.context }
2684
2386
  };
2685
2387
  }
2686
- function normalizeSdkVersion(value) {
2687
- return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9.+_-]{0,127}$/u.test(value) ? value : "unknown";
2688
- }
2689
- function normalizeOperation(value) {
2690
- return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,255}$/u.test(value) ? value : "unknown";
2691
- }
2692
- function normalizeErrorKind(value) {
2693
- return typeof value === "string" && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u.test(value) ? value : "Error";
2694
- }
2695
- function syntheticException(operation, kind) {
2696
- const error = new Error(EXCEPTION_MESSAGE);
2697
- error.name = kind;
2698
- error.stack = `${kind}: ${error.message}\n at CapxulSdkBoundary.${operation} (capxul-sdk-observation://boundary/${operation}:1:1)`;
2699
- return error;
2700
- }
2701
2388
  function isPromiseLike(value) {
2702
- return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
2703
- }
2704
- function isPlainObject(value) {
2705
- if (typeof value !== "object" || value === null) return false;
2706
- const prototype = Object.getPrototypeOf(value);
2707
- return prototype === Object.prototype || prototype === null;
2708
- }
2709
- function isCapxulResult(value) {
2710
- return isPlainObject(value) && typeof value.ok === "boolean";
2711
- }
2712
- function isFailedResult(value) {
2713
- return isCapxulResult(value) && value.ok === false && "error" in value;
2389
+ return (typeof value === "object" && value !== null || typeof value === "function") && "then" in value;
2714
2390
  }
2715
2391
  const SDK_VERSION = version;
2716
2392
  /**
@@ -2731,7 +2407,6 @@ const collectProductionFlowPorts = Effect.gen(function* () {
2731
2407
  identity: yield* IdentityPortTag,
2732
2408
  smartAccount: yield* SmartAccountPortTag,
2733
2409
  accountRead: yield* AccountReadPortTag,
2734
- subAccount: yield* SubAccountPortTag,
2735
2410
  bootstrap,
2736
2411
  clock,
2737
2412
  telemetry: yield* TelemetryPortTag,
@@ -2768,10 +2443,6 @@ function makeProductionAdapterLayerEntries(input) {
2768
2443
  name: "accountRead",
2769
2444
  layer: ConvexAccountLayer()
2770
2445
  },
2771
- {
2772
- name: "subAccount",
2773
- layer: ConvexSubAccountLayer(input.chainId)
2774
- },
2775
2446
  {
2776
2447
  name: "clock",
2777
2448
  layer: SystemClockLayer()
@@ -2804,7 +2475,7 @@ function mergeProductionAdapterLayers(entries) {
2804
2475
  }).reduce((current, layer) => Layer.merge(current, layer), Layer.empty);
2805
2476
  }
2806
2477
  function isConvexDependentLayer(name) {
2807
- return name === "identity" || name === "smartAccount" || name === "accountRead" || name === "subAccount" || name === "org";
2478
+ return name === "identity" || name === "smartAccount" || name === "accountRead" || name === "org";
2808
2479
  }
2809
2480
  function productionBootstrapPortLayer(bootstrap) {
2810
2481
  return Layer.succeed(BootstrapPortTag, bootstrap);
@@ -2863,7 +2534,19 @@ function productionConvexCallLayer(input, refreshConvexAuthRef) {
2863
2534
  function isRefreshableConvexCallPort(convexCall) {
2864
2535
  return "refreshAuth" in convexCall && typeof convexCall.refreshAuth === "function";
2865
2536
  }
2537
+ function resolveProductionObservability(input) {
2538
+ const observation = input.observability?.failures ?? input.observation;
2539
+ const telemetry = input.observability?.product ?? input.telemetry;
2540
+ const invocationObservability = input.invocationObservability;
2541
+ return {
2542
+ observation,
2543
+ telemetry,
2544
+ invocationObservation: invocationObservability?.failures ?? observation,
2545
+ invocationTelemetry: invocationObservability?.product ?? telemetry
2546
+ };
2547
+ }
2866
2548
  async function createProductionAdapters(input) {
2549
+ const { observation, telemetry, invocationObservation, invocationTelemetry } = resolveProductionObservability(input);
2867
2550
  const resolvedInput = resolveInput(input);
2868
2551
  if (!resolvedInput.ok) return resolvedInput;
2869
2552
  const scope = await Effect.runPromise(Scope.make());
@@ -2871,7 +2554,7 @@ async function createProductionAdapters(input) {
2871
2554
  const bootstrapLayer = HttpBootstrapLayer({
2872
2555
  bootstrapBaseUrl: resolvedInput.value.bootstrapBaseUrl,
2873
2556
  ...input.fetch === void 0 ? {} : { fetch: input.fetch },
2874
- ...input.observation === void 0 ? {} : { observation: input.observation }
2557
+ ...invocationObservation === void 0 ? {} : { observation: invocationObservation }
2875
2558
  });
2876
2559
  try {
2877
2560
  const bootstrapContext = await Effect.runPromise(Layer.buildWithScope(bootstrapLayer, scope));
@@ -2881,7 +2564,7 @@ async function createProductionAdapters(input) {
2881
2564
  ...resolvedInput.value.origin === void 0 ? {} : { origin: resolvedInput.value.origin }
2882
2565
  }));
2883
2566
  if (!bootstrapResult.ok) {
2884
- await emitBootstrapTelemetry(input.telemetry, {
2567
+ await emitBootstrapTelemetry(invocationTelemetry, {
2885
2568
  name: "bootstrap_failed",
2886
2569
  props: {
2887
2570
  ...bootstrapTelemetryEnvelope(input, resolvedInput.value),
@@ -2898,7 +2581,7 @@ async function createProductionAdapters(input) {
2898
2581
  }
2899
2582
  const runtimeUrlsResult = resolveRuntimeUrls(bootstrapResult.value, resolvedInput.value.runtime, input.authBaseUrl);
2900
2583
  if (!runtimeUrlsResult.ok) {
2901
- await emitBootstrapTelemetry(input.telemetry, {
2584
+ await emitBootstrapTelemetry(invocationTelemetry, {
2902
2585
  name: "bootstrap_failed",
2903
2586
  props: {
2904
2587
  ...bootstrapTelemetryEnvelope(input, resolvedInput.value),
@@ -2910,7 +2593,7 @@ async function createProductionAdapters(input) {
2910
2593
  return runtimeUrlsResult;
2911
2594
  }
2912
2595
  const runtimeUrls = runtimeUrlsResult;
2913
- await emitBootstrapTelemetry(input.telemetry, {
2596
+ await emitBootstrapTelemetry(invocationTelemetry, {
2914
2597
  name: "bootstrap_resolved",
2915
2598
  props: {
2916
2599
  ...bootstrapTelemetryEnvelope(input, resolvedInput.value),
@@ -2935,19 +2618,15 @@ async function createProductionAdapters(input) {
2935
2618
  runtimeUrls: runtimeUrls.value,
2936
2619
  chainId: bootstrapResult.value.chainId,
2937
2620
  applicationId: bootstrapResult.value.applicationId,
2938
- ...input.observation === void 0 ? {} : { observation: input.observation },
2621
+ ...observation === void 0 ? {} : { observation },
2939
2622
  ...input.authCache === void 0 ? {} : { authCache: input.authCache },
2940
- ...input.telemetry === void 0 ? {} : { telemetry: input.telemetry },
2623
+ ...telemetry === void 0 ? {} : { telemetry },
2941
2624
  ...injectedClient === void 0 ? {} : { convexClient: injectedClient },
2942
2625
  ...input.fetch === void 0 ? {} : { fetch: input.fetch },
2943
2626
  ...input.signal === void 0 ? {} : { signal: input.signal },
2944
2627
  ...input.resetSignerSession === void 0 ? {} : { resetSignerSession: input.resetSignerSession }
2945
2628
  }));
2946
- const applicationLayer = input.engineeringTelemetry === void 0 ? portsLayer : Layer.merge(portsLayer, makeEngineeringTelemetryLayer({
2947
- ...input.engineeringTelemetry,
2948
- producer: resolvedInput.value.runtime === "browser" ? "browser" : "server",
2949
- sdkVersion: SDK_VERSION
2950
- }));
2629
+ const applicationLayer = Layer.merge(portsLayer, optionalEngineeringTelemetryLayer(bootstrapResult.value.engineeringTelemetry, resolvedInput.value.runtime));
2951
2630
  const context = await Effect.runPromise(Layer.buildWithScope(applicationLayer, scope));
2952
2631
  return {
2953
2632
  ok: true,
@@ -2966,6 +2645,20 @@ async function createProductionAdapters(input) {
2966
2645
  };
2967
2646
  }
2968
2647
  }
2648
+ function optionalEngineeringTelemetryLayer(policy, runtime) {
2649
+ if (policy === void 0) return Layer.empty;
2650
+ try {
2651
+ return makeEngineeringTelemetryLayer({
2652
+ host: policy.host,
2653
+ headers: { authorization: `Bearer ${policy.projectToken}` },
2654
+ capxulEnv: policy.capxulEnv,
2655
+ producer: runtime === "browser" ? "browser" : "server",
2656
+ sdkVersion: SDK_VERSION
2657
+ });
2658
+ } catch {
2659
+ return Layer.empty;
2660
+ }
2661
+ }
2969
2662
  function refreshConvexAuthOnSession(authClient, refresh) {
2970
2663
  return {
2971
2664
  ...authClient,
@@ -2995,14 +2688,17 @@ function resetSignerSessionOnSignOut(authClient, resetRef) {
2995
2688
  };
2996
2689
  }
2997
2690
  async function createCapxulClient$1(input) {
2691
+ const invocationObservability = bindHostObservabilityInvocation(input.observability);
2692
+ const observation = invocationObservability?.failures ?? input.observation;
2998
2693
  const validation = validateCreateCapxulClientInput(input);
2999
- if (!validation.ok) return observeFailedResult(validation, input.observation, "createCapxulClient");
2694
+ if (!validation.ok) return observeFailedResult(validation, observation, "createCapxulClient");
3000
2695
  const resetSignerSession = { current: null };
3001
2696
  const adapters = await createProductionAdapters({
3002
2697
  ...input,
3003
- resetSignerSession
2698
+ resetSignerSession,
2699
+ ...invocationObservability === void 0 ? {} : { invocationObservability }
3004
2700
  });
3005
- if (!adapters.ok) return observeFailedResult(adapters, input.observation, "createCapxulClient");
2701
+ if (!adapters.ok) return observeFailedResult(adapters, observation, "createCapxulClient");
3006
2702
  try {
3007
2703
  const runtime = input.runtime ?? detectRuntime();
3008
2704
  const resolvedAuthBaseUrl = resolveBrowserAuthBaseUrl({
@@ -3039,6 +2735,7 @@ async function createCapxulClient$1(input) {
3039
2735
  ...input.signal === void 0 ? {} : { signal: input.signal },
3040
2736
  ...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs },
3041
2737
  invokeTimeoutMs: input.invokeTimeoutMs ?? 3e4,
2738
+ ...input.observability === void 0 ? {} : { hostObservationSnapshot: () => snapshotHostObservability(input.observability) },
3042
2739
  effectRunner: {
3043
2740
  runSync: Effect.runSyncWith(adapters.value.context),
3044
2741
  runPromise: Effect.runPromiseWith(adapters.value.context)
@@ -3067,7 +2764,7 @@ async function createCapxulClient$1(input) {
3067
2764
  return observeFailedResult({
3068
2765
  ok: false,
3069
2766
  error: toPublicError(cause, "createCapxulClient")
3070
- }, input.observation, "createCapxulClient");
2767
+ }, observation, "createCapxulClient");
3071
2768
  }
3072
2769
  }
3073
2770
  function validateCreateCapxulClientInput(input) {
@@ -3216,80 +2913,4 @@ async function createCapxulClient(input) {
3216
2913
  return createCapxulClient$1(input);
3217
2914
  }
3218
2915
  //#endregion
3219
- //#region src/telemetry/from-posthog.ts
3220
- /**
3221
- * Drop props that must never cross to a host-owned external sink. Today that is
3222
- * the `$exception` `details` blob: `captureException` serializes
3223
- * `CapxulError.details` (e.g. `{ asset, available, required }`, `{ name }`,
3224
- * `{ accountId }` — errors.ts) into it, and the shared redactor has no
3225
- * `$exception` rule, so it is stripped here at the boundary (infra#1037). The
3226
- * safe fields (error code, operation, failure_mode, the fixed leak-safe message,
3227
- * stack frames) are preserved.
3228
- */
3229
- function stripHostUnsafeProps(props) {
3230
- if (props === void 0) return void 0;
3231
- const { details: _details, ...safe } = props;
3232
- return safe;
3233
- }
3234
- /**
3235
- * Adapt the host's already-initialized posthog-like client into a
3236
- * `TelemetryPort` for the `telemetry` prop / input. This port SUPPLANTS the
3237
- * SDK's no-op default telemetry sink (`production.ts` binds it via
3238
- * `Layer.succeed`, not `compose` — there is no client-side success relay to
3239
- * compose with); it is additive to Capxul's backend first-party record and
3240
- * never owns the client.
3241
- */
3242
- function telemetryFromPostHog(client, options = {}) {
3243
- const active = () => {
3244
- if (client === null || client === void 0) return false;
3245
- try {
3246
- return typeof options.enabled === "function" ? options.enabled() : options.enabled ?? true;
3247
- } catch {
3248
- return false;
3249
- }
3250
- };
3251
- const contextProps = () => {
3252
- let raw;
3253
- try {
3254
- raw = typeof options.context === "function" ? options.context() : options.context;
3255
- } catch {
3256
- return {};
3257
- }
3258
- return observationContextProps(sanitizeObservationContext(raw));
3259
- };
3260
- return new PostHogTelemetryAdapter({
3261
- capture: (name, props) => {
3262
- if (!active() || client === null || client === void 0) return;
3263
- const event = stampTelemetryEnvelope({
3264
- name,
3265
- props
3266
- }, {
3267
- capxul_env: options.capxulEnv ?? "unknown",
3268
- producer: "sdk"
3269
- });
3270
- client.capture(name, {
3271
- ...stripHostUnsafeProps(event.props),
3272
- ...contextProps()
3273
- });
3274
- },
3275
- identify: (input) => {
3276
- if (!active() || client?.identify === void 0) return;
3277
- client.identify(input.distinctId, {
3278
- ...input.traits,
3279
- ...input.properties
3280
- });
3281
- },
3282
- group: (input) => {
3283
- if (!active() || client?.group === void 0) return;
3284
- client.group(input.groupType, input.groupKey, input.properties === void 0 ? void 0 : { ...input.properties });
3285
- },
3286
- reset: () => {
3287
- if (!active() || client?.reset === void 0) return;
3288
- client.reset();
3289
- }
3290
- });
3291
- }
3292
- //#endregion
3293
- export { CAPXUL_SDK_EXPECTED_OUTCOME_EVENT, CapxulError, captureException, captureExceptionSync, createCapxulClient, deriveDevPrivateKey, devPrivateKeySigner, eip1193AccountProvider, embeddedSigner, fromPostHog, injectedWalletSigner, isCapxulError, isSettingUpLifecycle, localPrivateKeyAccountProvider, openfortEmbeddedSigner, openfortEmbeddedSignerFromWallet, openfortEmbeddedWalletPort, destination as resolveIdentityDestination, telemetryFromPostHog, toCountryCode, toAddress as toEvmAddress };
3294
-
3295
- //# sourceMappingURL=index.mjs.map
2916
+ export { CAPXUL_PAYMENTS_V2_ADDRESS, CAPXUL_SDK_EXPECTED_OUTCOME_EVENT, CapxulError, captureException, captureExceptionSync, createCapxulClient, deriveDevPrivateKey, devPrivateKeySigner, eip1193AccountProvider, embeddedSigner, injectedWalletSigner, isCapxulError, isSettingUpLifecycle, localPrivateKeyAccountProvider, openfortEmbeddedSigner, openfortEmbeddedSignerFromWallet, openfortEmbeddedWalletPort, postHogObservability, destination as resolveIdentityDestination, toCountryCode, toAddress as toEvmAddress };