@owney/sdk 0.6.9-beta.1 → 0.6.9-beta.2

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.cjs CHANGED
@@ -26,7 +26,8 @@ __export(index_exports, {
26
26
  NotConnectedError: () => NotConnectedError,
27
27
  OwneyError: () => OwneyError,
28
28
  OwneySDK: () => OwneySDK,
29
- createOwneySIWX: () => createOwneySIWX
29
+ createOwneySIWX: () => createOwneySIWX,
30
+ setOwneyDebug: () => setOwneyDebug
30
31
  });
31
32
  module.exports = __toCommonJS(index_exports);
32
33
 
@@ -693,6 +694,23 @@ function splittingNeedsUpdate(current, desired) {
693
694
  return current.minSplits !== desired.minSplits;
694
695
  }
695
696
 
697
+ // src/lib/debug.ts
698
+ var configuredDebug = false;
699
+ function setOwneyDebug(enabled) {
700
+ configuredDebug = enabled;
701
+ }
702
+ function isOwneyDebug() {
703
+ return globalThis.__OWNEY_DEBUG__ === true || configuredDebug;
704
+ }
705
+ function debugLog(scope, message, data) {
706
+ if (!isOwneyDebug()) return;
707
+ if (data === void 0) {
708
+ console.log(`[${scope}] ${message}`);
709
+ } else {
710
+ console.log(`[${scope}] ${message}`, data);
711
+ }
712
+ }
713
+
696
714
  // src/agents/zyfai/zyfai.agent.ts
697
715
  var DEFAULT_ZYFAI_RPC_URLS = {
698
716
  8453: "https://base-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V",
@@ -1082,6 +1100,11 @@ var ZyfaiAgent = class {
1082
1100
  * activation.
1083
1101
  */
1084
1102
  async applyOrgPolicy(_state, _chainId, policy) {
1103
+ debugLog("zyfai:splitting", "applying org policy", {
1104
+ policy,
1105
+ // Per asset because Zyfai stores splitting under assetTypeSettings[asset].
1106
+ assets: SPLITTING_ASSETS
1107
+ });
1085
1108
  await Promise.all(
1086
1109
  SPLITTING_ASSETS.map((asset) => this.applySplitting(asset, policy))
1087
1110
  );
@@ -1090,8 +1113,30 @@ var ZyfaiAgent = class {
1090
1113
  try {
1091
1114
  const desired = toZyfaiSplitting(policy);
1092
1115
  const current = await this.sdk.getUserDetails(asset);
1093
- if (!splittingNeedsUpdate(current, desired)) return;
1094
- await this.sdk.updateUserProfile({ asset, ...desired });
1116
+ const currentSplitting = {
1117
+ splitting: current?.splitting,
1118
+ minSplits: current?.minSplits
1119
+ };
1120
+ const needsUpdate = splittingNeedsUpdate(current, desired);
1121
+ debugLog("zyfai:splitting", `${asset}: comparing`, {
1122
+ mode: policy.splittingMode,
1123
+ current: currentSplitting,
1124
+ desired,
1125
+ // Spelled out because the "why" is the non-obvious part: minSplits is
1126
+ // what separates automatic (1) from force (2-4), not `splitting`.
1127
+ decision: needsUpdate ? "will write \u2014 profile differs from the org policy" : "skipping \u2014 profile already matches"
1128
+ });
1129
+ if (!needsUpdate) return;
1130
+ const result = await this.sdk.updateUserProfile({ asset, ...desired });
1131
+ debugLog("zyfai:splitting", `${asset}: wrote updateUserProfile`, {
1132
+ sent: { asset, ...desired },
1133
+ // updateUserProfile re-reads the profile after PATCHing, so this is
1134
+ // Zyfai's own view of the result rather than an echo of what we sent.
1135
+ zyfaiNowReports: {
1136
+ splitting: result?.splitting,
1137
+ minSplits: result?.minSplits
1138
+ }
1139
+ });
1095
1140
  } catch (error) {
1096
1141
  console.warn(
1097
1142
  `[zyfai] applyOrgPolicy(${asset}) failed (non-fatal):`,
@@ -1271,7 +1316,13 @@ async function fetchOrgAgentConfig(apiKey) {
1271
1316
  return null;
1272
1317
  }
1273
1318
  const json = await res.json();
1274
- return json.success ? json.data ?? null : null;
1319
+ const policy = json.success ? json.data ?? null : null;
1320
+ debugLog(
1321
+ "owney-sdk",
1322
+ policy ? "org agent config: loaded" : "org agent config: none set by this partner \u2014 user profiles will be left as they are",
1323
+ policy ?? void 0
1324
+ );
1325
+ return policy;
1275
1326
  } catch (error) {
1276
1327
  console.warn(
1277
1328
  "[owney-sdk] Could not read org agent config (non-fatal):",
@@ -1907,6 +1958,7 @@ var OwneySDK = class {
1907
1958
  initializingAgentsPromise = null;
1908
1959
  constructor(config) {
1909
1960
  this.apiKey = config.apiKey;
1961
+ if (config.debug) setOwneyDebug(true);
1910
1962
  this.zyfaiRpcUrls = config.zyfaiRpcUrls;
1911
1963
  this.routingApiBaseUrl = config.routingApiBaseUrl;
1912
1964
  this.referralSource = config.referralSource;
@@ -2093,7 +2145,13 @@ var OwneySDK = class {
2093
2145
  * user's connect over.
2094
2146
  */
2095
2147
  async applyOrgPolicyTo(agent, state, chainId) {
2096
- if (!agent.applyOrgPolicy) return;
2148
+ if (!agent.applyOrgPolicy) {
2149
+ debugLog(
2150
+ "owney-sdk",
2151
+ `${agent.id}: no applyOrgPolicy \u2014 agent has no org-level knobs, skipping`
2152
+ );
2153
+ return;
2154
+ }
2097
2155
  try {
2098
2156
  const policy = await this.getOrgAgentConfig();
2099
2157
  if (!policy) return;
@@ -3227,5 +3285,6 @@ function createOwneySIWX(config) {
3227
3285
  NotConnectedError,
3228
3286
  OwneyError,
3229
3287
  OwneySDK,
3230
- createOwneySIWX
3288
+ createOwneySIWX,
3289
+ setOwneyDebug
3231
3290
  });
package/dist/index.d.cts CHANGED
@@ -21,6 +21,15 @@ interface OwneySDKConfig {
21
21
  * `createOwneySIWX` for apps that don't use the AppKit SIWX modal.
22
22
  */
23
23
  referralSource?: string;
24
+ /**
25
+ * Turn on the SDK's debug logging (default false). Traces the decisions that
26
+ * are otherwise invisible — notably how the organization's agent policy is
27
+ * compared against each user's Zyfai profile and whether it writes.
28
+ *
29
+ * Also switchable at runtime without a rebuild, which is what you want on an
30
+ * already-deployed app: set `globalThis.__OWNEY_DEBUG__ = true` in devtools.
31
+ */
32
+ debug?: boolean;
24
33
  }
25
34
  interface ConnectionState {
26
35
  provider: any;
@@ -594,6 +603,29 @@ declare class InvalidHistoryCursorError extends Error {
594
603
  constructor(message: string);
595
604
  }
596
605
 
606
+ /**
607
+ * Opt-in debug logging.
608
+ *
609
+ * The SDK is deliberately quiet: before this, `src/` contained no `console.log`
610
+ * at all, only `console.warn`/`console.error` for genuine faults. That is worth
611
+ * preserving — this runs inside every partner's app, on every user's connect, so
612
+ * unconditional chatter would land in end users' consoles forever.
613
+ *
614
+ * Two ways to turn it on:
615
+ *
616
+ * 1. From the app: new OwneySDK({ apiKey, debug: true })
617
+ * 2. From devtools, live: globalThis.__OWNEY_DEBUG__ = true
618
+ *
619
+ * (2) is the useful one when diagnosing something on an already-deployed app:
620
+ * the flag is read on every call, not captured once, so flipping it in the
621
+ * console takes effect on the next action without a rebuild or a republish.
622
+ */
623
+ declare global {
624
+ var __OWNEY_DEBUG__: boolean | undefined;
625
+ }
626
+ /** Enable/disable debug logging programmatically. */
627
+ declare function setOwneyDebug(enabled: boolean): void;
628
+
597
629
  type OwneySIWXConfig = {
598
630
  /** Owney/Zyfai API key — same value passed to `new OwneySDK({ apiKey })`. */
599
631
  apiKey: string;
@@ -607,4 +639,4 @@ type OwneySIWXConfig = {
607
639
  */
608
640
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
609
641
 
610
- export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, AllocationApyOptions, ApyByChainAndAsset, ApyHistoryPoint, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
642
+ export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, AllocationApyOptions, ApyByChainAndAsset, ApyHistoryPoint, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX, setOwneyDebug };
package/dist/index.d.ts CHANGED
@@ -21,6 +21,15 @@ interface OwneySDKConfig {
21
21
  * `createOwneySIWX` for apps that don't use the AppKit SIWX modal.
22
22
  */
23
23
  referralSource?: string;
24
+ /**
25
+ * Turn on the SDK's debug logging (default false). Traces the decisions that
26
+ * are otherwise invisible — notably how the organization's agent policy is
27
+ * compared against each user's Zyfai profile and whether it writes.
28
+ *
29
+ * Also switchable at runtime without a rebuild, which is what you want on an
30
+ * already-deployed app: set `globalThis.__OWNEY_DEBUG__ = true` in devtools.
31
+ */
32
+ debug?: boolean;
24
33
  }
25
34
  interface ConnectionState {
26
35
  provider: any;
@@ -594,6 +603,29 @@ declare class InvalidHistoryCursorError extends Error {
594
603
  constructor(message: string);
595
604
  }
596
605
 
606
+ /**
607
+ * Opt-in debug logging.
608
+ *
609
+ * The SDK is deliberately quiet: before this, `src/` contained no `console.log`
610
+ * at all, only `console.warn`/`console.error` for genuine faults. That is worth
611
+ * preserving — this runs inside every partner's app, on every user's connect, so
612
+ * unconditional chatter would land in end users' consoles forever.
613
+ *
614
+ * Two ways to turn it on:
615
+ *
616
+ * 1. From the app: new OwneySDK({ apiKey, debug: true })
617
+ * 2. From devtools, live: globalThis.__OWNEY_DEBUG__ = true
618
+ *
619
+ * (2) is the useful one when diagnosing something on an already-deployed app:
620
+ * the flag is read on every call, not captured once, so flipping it in the
621
+ * console takes effect on the next action without a rebuild or a republish.
622
+ */
623
+ declare global {
624
+ var __OWNEY_DEBUG__: boolean | undefined;
625
+ }
626
+ /** Enable/disable debug logging programmatically. */
627
+ declare function setOwneyDebug(enabled: boolean): void;
628
+
597
629
  type OwneySIWXConfig = {
598
630
  /** Owney/Zyfai API key — same value passed to `new OwneySDK({ apiKey })`. */
599
631
  apiKey: string;
@@ -607,4 +639,4 @@ type OwneySIWXConfig = {
607
639
  */
608
640
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
609
641
 
610
- export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, AllocationApyOptions, ApyByChainAndAsset, ApyHistoryPoint, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
642
+ export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, AllocationApyOptions, ApyByChainAndAsset, ApyHistoryPoint, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX, setOwneyDebug };
package/dist/index.js CHANGED
@@ -661,6 +661,23 @@ function splittingNeedsUpdate(current, desired) {
661
661
  return current.minSplits !== desired.minSplits;
662
662
  }
663
663
 
664
+ // src/lib/debug.ts
665
+ var configuredDebug = false;
666
+ function setOwneyDebug(enabled) {
667
+ configuredDebug = enabled;
668
+ }
669
+ function isOwneyDebug() {
670
+ return globalThis.__OWNEY_DEBUG__ === true || configuredDebug;
671
+ }
672
+ function debugLog(scope, message, data) {
673
+ if (!isOwneyDebug()) return;
674
+ if (data === void 0) {
675
+ console.log(`[${scope}] ${message}`);
676
+ } else {
677
+ console.log(`[${scope}] ${message}`, data);
678
+ }
679
+ }
680
+
664
681
  // src/agents/zyfai/zyfai.agent.ts
665
682
  var DEFAULT_ZYFAI_RPC_URLS = {
666
683
  8453: "https://base-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V",
@@ -1050,6 +1067,11 @@ var ZyfaiAgent = class {
1050
1067
  * activation.
1051
1068
  */
1052
1069
  async applyOrgPolicy(_state, _chainId, policy) {
1070
+ debugLog("zyfai:splitting", "applying org policy", {
1071
+ policy,
1072
+ // Per asset because Zyfai stores splitting under assetTypeSettings[asset].
1073
+ assets: SPLITTING_ASSETS
1074
+ });
1053
1075
  await Promise.all(
1054
1076
  SPLITTING_ASSETS.map((asset) => this.applySplitting(asset, policy))
1055
1077
  );
@@ -1058,8 +1080,30 @@ var ZyfaiAgent = class {
1058
1080
  try {
1059
1081
  const desired = toZyfaiSplitting(policy);
1060
1082
  const current = await this.sdk.getUserDetails(asset);
1061
- if (!splittingNeedsUpdate(current, desired)) return;
1062
- await this.sdk.updateUserProfile({ asset, ...desired });
1083
+ const currentSplitting = {
1084
+ splitting: current?.splitting,
1085
+ minSplits: current?.minSplits
1086
+ };
1087
+ const needsUpdate = splittingNeedsUpdate(current, desired);
1088
+ debugLog("zyfai:splitting", `${asset}: comparing`, {
1089
+ mode: policy.splittingMode,
1090
+ current: currentSplitting,
1091
+ desired,
1092
+ // Spelled out because the "why" is the non-obvious part: minSplits is
1093
+ // what separates automatic (1) from force (2-4), not `splitting`.
1094
+ decision: needsUpdate ? "will write \u2014 profile differs from the org policy" : "skipping \u2014 profile already matches"
1095
+ });
1096
+ if (!needsUpdate) return;
1097
+ const result = await this.sdk.updateUserProfile({ asset, ...desired });
1098
+ debugLog("zyfai:splitting", `${asset}: wrote updateUserProfile`, {
1099
+ sent: { asset, ...desired },
1100
+ // updateUserProfile re-reads the profile after PATCHing, so this is
1101
+ // Zyfai's own view of the result rather than an echo of what we sent.
1102
+ zyfaiNowReports: {
1103
+ splitting: result?.splitting,
1104
+ minSplits: result?.minSplits
1105
+ }
1106
+ });
1063
1107
  } catch (error) {
1064
1108
  console.warn(
1065
1109
  `[zyfai] applyOrgPolicy(${asset}) failed (non-fatal):`,
@@ -1239,7 +1283,13 @@ async function fetchOrgAgentConfig(apiKey) {
1239
1283
  return null;
1240
1284
  }
1241
1285
  const json = await res.json();
1242
- return json.success ? json.data ?? null : null;
1286
+ const policy = json.success ? json.data ?? null : null;
1287
+ debugLog(
1288
+ "owney-sdk",
1289
+ policy ? "org agent config: loaded" : "org agent config: none set by this partner \u2014 user profiles will be left as they are",
1290
+ policy ?? void 0
1291
+ );
1292
+ return policy;
1243
1293
  } catch (error) {
1244
1294
  console.warn(
1245
1295
  "[owney-sdk] Could not read org agent config (non-fatal):",
@@ -1879,6 +1929,7 @@ var OwneySDK = class {
1879
1929
  initializingAgentsPromise = null;
1880
1930
  constructor(config) {
1881
1931
  this.apiKey = config.apiKey;
1932
+ if (config.debug) setOwneyDebug(true);
1882
1933
  this.zyfaiRpcUrls = config.zyfaiRpcUrls;
1883
1934
  this.routingApiBaseUrl = config.routingApiBaseUrl;
1884
1935
  this.referralSource = config.referralSource;
@@ -2065,7 +2116,13 @@ var OwneySDK = class {
2065
2116
  * user's connect over.
2066
2117
  */
2067
2118
  async applyOrgPolicyTo(agent, state, chainId) {
2068
- if (!agent.applyOrgPolicy) return;
2119
+ if (!agent.applyOrgPolicy) {
2120
+ debugLog(
2121
+ "owney-sdk",
2122
+ `${agent.id}: no applyOrgPolicy \u2014 agent has no org-level knobs, skipping`
2123
+ );
2124
+ return;
2125
+ }
2069
2126
  try {
2070
2127
  const policy = await this.getOrgAgentConfig();
2071
2128
  if (!policy) return;
@@ -3198,5 +3255,6 @@ export {
3198
3255
  NotConnectedError,
3199
3256
  OwneyError,
3200
3257
  OwneySDK,
3201
- createOwneySIWX
3258
+ createOwneySIWX,
3259
+ setOwneyDebug
3202
3260
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.6.9-beta.1",
3
+ "version": "0.6.9-beta.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",