@owney/sdk 0.7.14-beta.0 → 0.7.15-beta.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.cjs CHANGED
@@ -1864,8 +1864,8 @@ var ZyfaiAgent = class _ZyfaiAgent {
1864
1864
 
1865
1865
  // src/lib/routing-api.ts
1866
1866
  var ROUTING_API_BASE_URL = "https://owney-routing-api-243946518160.europe-west4.run.app";
1867
- async function fetchOrgAgentConfig(apiKey) {
1868
- const url = `${ROUTING_API_BASE_URL}/api/v1/agent/org-config`;
1867
+ async function fetchOrgAgentConfig(apiKey, baseUrl = ROUTING_API_BASE_URL) {
1868
+ const url = `${baseUrl}/api/v1/agent/org-config`;
1869
1869
  try {
1870
1870
  const res = await fetch(url, {
1871
1871
  method: "GET",
@@ -1898,8 +1898,8 @@ async function fetchOrgAgentConfig(apiKey) {
1898
1898
  return null;
1899
1899
  }
1900
1900
  }
1901
- async function fetchAgentKeys(apiKey) {
1902
- const url = `${ROUTING_API_BASE_URL}/api/v1/agent/keys`;
1901
+ async function fetchAgentKeys(apiKey, baseUrl = ROUTING_API_BASE_URL) {
1902
+ const url = `${baseUrl}/api/v1/agent/keys`;
1903
1903
  const res = await fetch(url, {
1904
1904
  method: "GET",
1905
1905
  headers: {
@@ -1928,9 +1928,9 @@ async function fetchAgentKeys(apiKey) {
1928
1928
 
1929
1929
  // src/lib/health-report.ts
1930
1930
  var ROUTING_API_BASE_URL2 = "https://owney-routing-api-243946518160.europe-west4.run.app";
1931
- async function reportAgentFailure(apiKey, agentType, errorCode) {
1931
+ async function reportAgentFailure(apiKey, agentType, errorCode, baseUrl = ROUTING_API_BASE_URL2) {
1932
1932
  try {
1933
- await fetch(`${ROUTING_API_BASE_URL2}/api/v1/agent/health-report`, {
1933
+ await fetch(`${baseUrl}/api/v1/agent/health-report`, {
1934
1934
  method: "POST",
1935
1935
  headers: {
1936
1936
  "Content-Type": "application/json",
@@ -1949,12 +1949,12 @@ async function reportAgentFailure(apiKey, agentType, errorCode) {
1949
1949
  );
1950
1950
  }
1951
1951
  }
1952
- async function withFailureReporting(apiKey, agentType, fn) {
1952
+ async function withFailureReporting(apiKey, agentType, fn, baseUrl) {
1953
1953
  try {
1954
1954
  return await fn();
1955
1955
  } catch (err) {
1956
1956
  const errorCode = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
1957
- void reportAgentFailure(apiKey, agentType, errorCode);
1957
+ void reportAgentFailure(apiKey, agentType, errorCode, baseUrl);
1958
1958
  throw err;
1959
1959
  }
1960
1960
  }
@@ -2855,7 +2855,10 @@ var OwneySDK = class {
2855
2855
  async getOrgAgentConfig() {
2856
2856
  if (this.orgAgentConfig !== void 0) return this.orgAgentConfig;
2857
2857
  if (!this.orgAgentConfigPromise) {
2858
- this.orgAgentConfigPromise = fetchOrgAgentConfig(this.apiKey).then(
2858
+ this.orgAgentConfigPromise = fetchOrgAgentConfig(
2859
+ this.apiKey,
2860
+ this.routingApiBaseUrl
2861
+ ).then(
2859
2862
  (config) => {
2860
2863
  this.orgAgentConfig = config;
2861
2864
  return config;
@@ -2895,7 +2898,10 @@ var OwneySDK = class {
2895
2898
  if (this.agents.size > 0) return;
2896
2899
  if (!this.initializingAgentsPromise) {
2897
2900
  this.initializingAgentsPromise = (async () => {
2898
- const agentKeys = await fetchAgentKeys(this.apiKey);
2901
+ const agentKeys = await fetchAgentKeys(
2902
+ this.apiKey,
2903
+ this.routingApiBaseUrl
2904
+ );
2899
2905
  this.disabledAgents.clear();
2900
2906
  for (const { key: key2, agent_type, is_enabled } of agentKeys) {
2901
2907
  const agent = this.createAgent(agent_type, key2);
@@ -3151,7 +3157,8 @@ var OwneySDK = class {
3151
3157
  amount,
3152
3158
  asset,
3153
3159
  callback
3154
- )
3160
+ ),
3161
+ this.routingApiBaseUrl
3155
3162
  );
3156
3163
  let approvalAttempted = false;
3157
3164
  for (; ; ) {
@@ -3301,7 +3308,8 @@ var OwneySDK = class {
3301
3308
  return withFailureReporting(
3302
3309
  this.apiKey,
3303
3310
  agent.id,
3304
- () => agent.withdraw(state, chainId, token, amount)
3311
+ () => agent.withdraw(state, chainId, token, amount),
3312
+ this.routingApiBaseUrl
3305
3313
  );
3306
3314
  }
3307
3315
  const eligibleAgents = this.getEligibleAgents(chainId, asset);
@@ -3315,7 +3323,12 @@ var OwneySDK = class {
3315
3323
  console.error(`withdraw failed for agent "${agent.id}":`, err);
3316
3324
  agentErrors2[agent.id] = err instanceof Error ? err.message : String(err);
3317
3325
  const code = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
3318
- void reportAgentFailure(this.apiKey, agent.id, code);
3326
+ void reportAgentFailure(
3327
+ this.apiKey,
3328
+ agent.id,
3329
+ code,
3330
+ this.routingApiBaseUrl
3331
+ );
3319
3332
  }
3320
3333
  }
3321
3334
  if (Object.keys(results2).length === 0) {
@@ -3384,7 +3397,12 @@ var OwneySDK = class {
3384
3397
  console.error(`withdraw failed for agent "${p.agent.id}":`, err);
3385
3398
  agentErrors[p.agent.id] = err instanceof Error ? err.message : String(err);
3386
3399
  const code = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
3387
- void reportAgentFailure(this.apiKey, p.agent.id, code);
3400
+ void reportAgentFailure(
3401
+ this.apiKey,
3402
+ p.agent.id,
3403
+ code,
3404
+ this.routingApiBaseUrl
3405
+ );
3388
3406
  const failedAmount = p.planned;
3389
3407
  p.planned = 0n;
3390
3408
  redistributeShare(plans, i, failedAmount);
package/dist/index.d.cts CHANGED
@@ -9,16 +9,16 @@ interface OwneySDKConfig {
9
9
  */
10
10
  zyfaiRpcUrls?: ZyfaiRpcUrlsConfig;
11
11
  /**
12
- * Optional override for the Owney routing API base URL used by the sponsored
13
- * deposit callbacks (defaults to the OWNEY_ROUTING_API_BASE_URL env var, then
14
- * the production URL). Set this to point at a local/staging routing API,
12
+ * Optional override for the Owney routing API base URL used by all routing
13
+ * calls (defaults to the OWNEY_ROUTING_API_BASE_URL env var, then the
14
+ * production URL). Set this to point at a local/staging routing API,
15
15
  * e.g. "http://localhost:3000", when testing sponsor changes.
16
16
  */
17
17
  routingApiBaseUrl?: string;
18
18
  /**
19
19
  * Optional attribution tag forwarded to Zyfai's /auth/login when the SDK
20
- * authenticates (e.g. "delos"). Replaces the equivalent option on
21
- * `createOwneySIWX` for apps that don't use the AppKit SIWX modal.
20
+ * authenticates. Replaces the equivalent option on `createOwneySIWX`
21
+ * for apps that don't use the AppKit SIWX modal.
22
22
  */
23
23
  referralSource?: string;
24
24
  /**
package/dist/index.d.ts CHANGED
@@ -9,16 +9,16 @@ interface OwneySDKConfig {
9
9
  */
10
10
  zyfaiRpcUrls?: ZyfaiRpcUrlsConfig;
11
11
  /**
12
- * Optional override for the Owney routing API base URL used by the sponsored
13
- * deposit callbacks (defaults to the OWNEY_ROUTING_API_BASE_URL env var, then
14
- * the production URL). Set this to point at a local/staging routing API,
12
+ * Optional override for the Owney routing API base URL used by all routing
13
+ * calls (defaults to the OWNEY_ROUTING_API_BASE_URL env var, then the
14
+ * production URL). Set this to point at a local/staging routing API,
15
15
  * e.g. "http://localhost:3000", when testing sponsor changes.
16
16
  */
17
17
  routingApiBaseUrl?: string;
18
18
  /**
19
19
  * Optional attribution tag forwarded to Zyfai's /auth/login when the SDK
20
- * authenticates (e.g. "delos"). Replaces the equivalent option on
21
- * `createOwneySIWX` for apps that don't use the AppKit SIWX modal.
20
+ * authenticates. Replaces the equivalent option on `createOwneySIWX`
21
+ * for apps that don't use the AppKit SIWX modal.
22
22
  */
23
23
  referralSource?: string;
24
24
  /**
package/dist/index.js CHANGED
@@ -1831,8 +1831,8 @@ var ZyfaiAgent = class _ZyfaiAgent {
1831
1831
 
1832
1832
  // src/lib/routing-api.ts
1833
1833
  var ROUTING_API_BASE_URL = "https://owney-routing-api-243946518160.europe-west4.run.app";
1834
- async function fetchOrgAgentConfig(apiKey) {
1835
- const url = `${ROUTING_API_BASE_URL}/api/v1/agent/org-config`;
1834
+ async function fetchOrgAgentConfig(apiKey, baseUrl = ROUTING_API_BASE_URL) {
1835
+ const url = `${baseUrl}/api/v1/agent/org-config`;
1836
1836
  try {
1837
1837
  const res = await fetch(url, {
1838
1838
  method: "GET",
@@ -1865,8 +1865,8 @@ async function fetchOrgAgentConfig(apiKey) {
1865
1865
  return null;
1866
1866
  }
1867
1867
  }
1868
- async function fetchAgentKeys(apiKey) {
1869
- const url = `${ROUTING_API_BASE_URL}/api/v1/agent/keys`;
1868
+ async function fetchAgentKeys(apiKey, baseUrl = ROUTING_API_BASE_URL) {
1869
+ const url = `${baseUrl}/api/v1/agent/keys`;
1870
1870
  const res = await fetch(url, {
1871
1871
  method: "GET",
1872
1872
  headers: {
@@ -1895,9 +1895,9 @@ async function fetchAgentKeys(apiKey) {
1895
1895
 
1896
1896
  // src/lib/health-report.ts
1897
1897
  var ROUTING_API_BASE_URL2 = "https://owney-routing-api-243946518160.europe-west4.run.app";
1898
- async function reportAgentFailure(apiKey, agentType, errorCode) {
1898
+ async function reportAgentFailure(apiKey, agentType, errorCode, baseUrl = ROUTING_API_BASE_URL2) {
1899
1899
  try {
1900
- await fetch(`${ROUTING_API_BASE_URL2}/api/v1/agent/health-report`, {
1900
+ await fetch(`${baseUrl}/api/v1/agent/health-report`, {
1901
1901
  method: "POST",
1902
1902
  headers: {
1903
1903
  "Content-Type": "application/json",
@@ -1916,12 +1916,12 @@ async function reportAgentFailure(apiKey, agentType, errorCode) {
1916
1916
  );
1917
1917
  }
1918
1918
  }
1919
- async function withFailureReporting(apiKey, agentType, fn) {
1919
+ async function withFailureReporting(apiKey, agentType, fn, baseUrl) {
1920
1920
  try {
1921
1921
  return await fn();
1922
1922
  } catch (err) {
1923
1923
  const errorCode = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
1924
- void reportAgentFailure(apiKey, agentType, errorCode);
1924
+ void reportAgentFailure(apiKey, agentType, errorCode, baseUrl);
1925
1925
  throw err;
1926
1926
  }
1927
1927
  }
@@ -2826,7 +2826,10 @@ var OwneySDK = class {
2826
2826
  async getOrgAgentConfig() {
2827
2827
  if (this.orgAgentConfig !== void 0) return this.orgAgentConfig;
2828
2828
  if (!this.orgAgentConfigPromise) {
2829
- this.orgAgentConfigPromise = fetchOrgAgentConfig(this.apiKey).then(
2829
+ this.orgAgentConfigPromise = fetchOrgAgentConfig(
2830
+ this.apiKey,
2831
+ this.routingApiBaseUrl
2832
+ ).then(
2830
2833
  (config) => {
2831
2834
  this.orgAgentConfig = config;
2832
2835
  return config;
@@ -2866,7 +2869,10 @@ var OwneySDK = class {
2866
2869
  if (this.agents.size > 0) return;
2867
2870
  if (!this.initializingAgentsPromise) {
2868
2871
  this.initializingAgentsPromise = (async () => {
2869
- const agentKeys = await fetchAgentKeys(this.apiKey);
2872
+ const agentKeys = await fetchAgentKeys(
2873
+ this.apiKey,
2874
+ this.routingApiBaseUrl
2875
+ );
2870
2876
  this.disabledAgents.clear();
2871
2877
  for (const { key: key2, agent_type, is_enabled } of agentKeys) {
2872
2878
  const agent = this.createAgent(agent_type, key2);
@@ -3122,7 +3128,8 @@ var OwneySDK = class {
3122
3128
  amount,
3123
3129
  asset,
3124
3130
  callback
3125
- )
3131
+ ),
3132
+ this.routingApiBaseUrl
3126
3133
  );
3127
3134
  let approvalAttempted = false;
3128
3135
  for (; ; ) {
@@ -3272,7 +3279,8 @@ var OwneySDK = class {
3272
3279
  return withFailureReporting(
3273
3280
  this.apiKey,
3274
3281
  agent.id,
3275
- () => agent.withdraw(state, chainId, token, amount)
3282
+ () => agent.withdraw(state, chainId, token, amount),
3283
+ this.routingApiBaseUrl
3276
3284
  );
3277
3285
  }
3278
3286
  const eligibleAgents = this.getEligibleAgents(chainId, asset);
@@ -3286,7 +3294,12 @@ var OwneySDK = class {
3286
3294
  console.error(`withdraw failed for agent "${agent.id}":`, err);
3287
3295
  agentErrors2[agent.id] = err instanceof Error ? err.message : String(err);
3288
3296
  const code = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
3289
- void reportAgentFailure(this.apiKey, agent.id, code);
3297
+ void reportAgentFailure(
3298
+ this.apiKey,
3299
+ agent.id,
3300
+ code,
3301
+ this.routingApiBaseUrl
3302
+ );
3290
3303
  }
3291
3304
  }
3292
3305
  if (Object.keys(results2).length === 0) {
@@ -3355,7 +3368,12 @@ var OwneySDK = class {
3355
3368
  console.error(`withdraw failed for agent "${p.agent.id}":`, err);
3356
3369
  agentErrors[p.agent.id] = err instanceof Error ? err.message : String(err);
3357
3370
  const code = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
3358
- void reportAgentFailure(this.apiKey, p.agent.id, code);
3371
+ void reportAgentFailure(
3372
+ this.apiKey,
3373
+ p.agent.id,
3374
+ code,
3375
+ this.routingApiBaseUrl
3376
+ );
3359
3377
  const failedAmount = p.planned;
3360
3378
  p.planned = 0n;
3361
3379
  redistributeShare(plans, i, failedAmount);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.14-beta.0",
3
+ "version": "0.7.15-beta.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",