@owney/sdk 0.7.16-beta.0 → 0.7.16
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 +32 -14
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +32 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1886,8 +1886,8 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
1886
1886
|
|
|
1887
1887
|
// src/lib/routing-api.ts
|
|
1888
1888
|
var ROUTING_API_BASE_URL = "https://owney-routing-api-243946518160.europe-west4.run.app";
|
|
1889
|
-
async function fetchOrgAgentConfig(apiKey) {
|
|
1890
|
-
const url = `${
|
|
1889
|
+
async function fetchOrgAgentConfig(apiKey, baseUrl = ROUTING_API_BASE_URL) {
|
|
1890
|
+
const url = `${baseUrl}/api/v1/agent/org-config`;
|
|
1891
1891
|
try {
|
|
1892
1892
|
const res = await fetch(url, {
|
|
1893
1893
|
method: "GET",
|
|
@@ -1920,8 +1920,8 @@ async function fetchOrgAgentConfig(apiKey) {
|
|
|
1920
1920
|
return null;
|
|
1921
1921
|
}
|
|
1922
1922
|
}
|
|
1923
|
-
async function fetchAgentKeys(apiKey) {
|
|
1924
|
-
const url = `${
|
|
1923
|
+
async function fetchAgentKeys(apiKey, baseUrl = ROUTING_API_BASE_URL) {
|
|
1924
|
+
const url = `${baseUrl}/api/v1/agent/keys`;
|
|
1925
1925
|
const res = await fetch(url, {
|
|
1926
1926
|
method: "GET",
|
|
1927
1927
|
headers: {
|
|
@@ -1950,9 +1950,9 @@ async function fetchAgentKeys(apiKey) {
|
|
|
1950
1950
|
|
|
1951
1951
|
// src/lib/health-report.ts
|
|
1952
1952
|
var ROUTING_API_BASE_URL2 = "https://owney-routing-api-243946518160.europe-west4.run.app";
|
|
1953
|
-
async function reportAgentFailure(apiKey, agentType, errorCode) {
|
|
1953
|
+
async function reportAgentFailure(apiKey, agentType, errorCode, baseUrl = ROUTING_API_BASE_URL2) {
|
|
1954
1954
|
try {
|
|
1955
|
-
await fetch(`${
|
|
1955
|
+
await fetch(`${baseUrl}/api/v1/agent/health-report`, {
|
|
1956
1956
|
method: "POST",
|
|
1957
1957
|
headers: {
|
|
1958
1958
|
"Content-Type": "application/json",
|
|
@@ -1971,12 +1971,12 @@ async function reportAgentFailure(apiKey, agentType, errorCode) {
|
|
|
1971
1971
|
);
|
|
1972
1972
|
}
|
|
1973
1973
|
}
|
|
1974
|
-
async function withFailureReporting(apiKey, agentType, fn) {
|
|
1974
|
+
async function withFailureReporting(apiKey, agentType, fn, baseUrl) {
|
|
1975
1975
|
try {
|
|
1976
1976
|
return await fn();
|
|
1977
1977
|
} catch (err) {
|
|
1978
1978
|
const errorCode = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
|
|
1979
|
-
void reportAgentFailure(apiKey, agentType, errorCode);
|
|
1979
|
+
void reportAgentFailure(apiKey, agentType, errorCode, baseUrl);
|
|
1980
1980
|
throw err;
|
|
1981
1981
|
}
|
|
1982
1982
|
}
|
|
@@ -2877,7 +2877,10 @@ var OwneySDK = class {
|
|
|
2877
2877
|
async getOrgAgentConfig() {
|
|
2878
2878
|
if (this.orgAgentConfig !== void 0) return this.orgAgentConfig;
|
|
2879
2879
|
if (!this.orgAgentConfigPromise) {
|
|
2880
|
-
this.orgAgentConfigPromise = fetchOrgAgentConfig(
|
|
2880
|
+
this.orgAgentConfigPromise = fetchOrgAgentConfig(
|
|
2881
|
+
this.apiKey,
|
|
2882
|
+
this.routingApiBaseUrl
|
|
2883
|
+
).then(
|
|
2881
2884
|
(config) => {
|
|
2882
2885
|
this.orgAgentConfig = config;
|
|
2883
2886
|
return config;
|
|
@@ -2917,7 +2920,10 @@ var OwneySDK = class {
|
|
|
2917
2920
|
if (this.agents.size > 0) return;
|
|
2918
2921
|
if (!this.initializingAgentsPromise) {
|
|
2919
2922
|
this.initializingAgentsPromise = (async () => {
|
|
2920
|
-
const agentKeys = await fetchAgentKeys(
|
|
2923
|
+
const agentKeys = await fetchAgentKeys(
|
|
2924
|
+
this.apiKey,
|
|
2925
|
+
this.routingApiBaseUrl
|
|
2926
|
+
);
|
|
2921
2927
|
this.disabledAgents.clear();
|
|
2922
2928
|
for (const { key: key2, agent_type, is_enabled } of agentKeys) {
|
|
2923
2929
|
const agent = this.createAgent(agent_type, key2);
|
|
@@ -3173,7 +3179,8 @@ var OwneySDK = class {
|
|
|
3173
3179
|
amount,
|
|
3174
3180
|
asset,
|
|
3175
3181
|
callback
|
|
3176
|
-
)
|
|
3182
|
+
),
|
|
3183
|
+
this.routingApiBaseUrl
|
|
3177
3184
|
);
|
|
3178
3185
|
let approvalAttempted = false;
|
|
3179
3186
|
for (; ; ) {
|
|
@@ -3323,7 +3330,8 @@ var OwneySDK = class {
|
|
|
3323
3330
|
return withFailureReporting(
|
|
3324
3331
|
this.apiKey,
|
|
3325
3332
|
agent.id,
|
|
3326
|
-
() => agent.withdraw(state, chainId, token, amount)
|
|
3333
|
+
() => agent.withdraw(state, chainId, token, amount),
|
|
3334
|
+
this.routingApiBaseUrl
|
|
3327
3335
|
);
|
|
3328
3336
|
}
|
|
3329
3337
|
const eligibleAgents = this.getEligibleAgents(chainId, asset);
|
|
@@ -3337,7 +3345,12 @@ var OwneySDK = class {
|
|
|
3337
3345
|
console.error(`withdraw failed for agent "${agent.id}":`, err);
|
|
3338
3346
|
agentErrors2[agent.id] = err instanceof Error ? err.message : String(err);
|
|
3339
3347
|
const code = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
|
|
3340
|
-
void reportAgentFailure(
|
|
3348
|
+
void reportAgentFailure(
|
|
3349
|
+
this.apiKey,
|
|
3350
|
+
agent.id,
|
|
3351
|
+
code,
|
|
3352
|
+
this.routingApiBaseUrl
|
|
3353
|
+
);
|
|
3341
3354
|
}
|
|
3342
3355
|
}
|
|
3343
3356
|
if (Object.keys(results2).length === 0) {
|
|
@@ -3406,7 +3419,12 @@ var OwneySDK = class {
|
|
|
3406
3419
|
console.error(`withdraw failed for agent "${p.agent.id}":`, err);
|
|
3407
3420
|
agentErrors[p.agent.id] = err instanceof Error ? err.message : String(err);
|
|
3408
3421
|
const code = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
|
|
3409
|
-
void reportAgentFailure(
|
|
3422
|
+
void reportAgentFailure(
|
|
3423
|
+
this.apiKey,
|
|
3424
|
+
p.agent.id,
|
|
3425
|
+
code,
|
|
3426
|
+
this.routingApiBaseUrl
|
|
3427
|
+
);
|
|
3410
3428
|
const failedAmount = p.planned;
|
|
3411
3429
|
p.planned = 0n;
|
|
3412
3430
|
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
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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
|
|
21
|
-
*
|
|
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
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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
|
|
21
|
-
*
|
|
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
|
@@ -1853,8 +1853,8 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
1853
1853
|
|
|
1854
1854
|
// src/lib/routing-api.ts
|
|
1855
1855
|
var ROUTING_API_BASE_URL = "https://owney-routing-api-243946518160.europe-west4.run.app";
|
|
1856
|
-
async function fetchOrgAgentConfig(apiKey) {
|
|
1857
|
-
const url = `${
|
|
1856
|
+
async function fetchOrgAgentConfig(apiKey, baseUrl = ROUTING_API_BASE_URL) {
|
|
1857
|
+
const url = `${baseUrl}/api/v1/agent/org-config`;
|
|
1858
1858
|
try {
|
|
1859
1859
|
const res = await fetch(url, {
|
|
1860
1860
|
method: "GET",
|
|
@@ -1887,8 +1887,8 @@ async function fetchOrgAgentConfig(apiKey) {
|
|
|
1887
1887
|
return null;
|
|
1888
1888
|
}
|
|
1889
1889
|
}
|
|
1890
|
-
async function fetchAgentKeys(apiKey) {
|
|
1891
|
-
const url = `${
|
|
1890
|
+
async function fetchAgentKeys(apiKey, baseUrl = ROUTING_API_BASE_URL) {
|
|
1891
|
+
const url = `${baseUrl}/api/v1/agent/keys`;
|
|
1892
1892
|
const res = await fetch(url, {
|
|
1893
1893
|
method: "GET",
|
|
1894
1894
|
headers: {
|
|
@@ -1917,9 +1917,9 @@ async function fetchAgentKeys(apiKey) {
|
|
|
1917
1917
|
|
|
1918
1918
|
// src/lib/health-report.ts
|
|
1919
1919
|
var ROUTING_API_BASE_URL2 = "https://owney-routing-api-243946518160.europe-west4.run.app";
|
|
1920
|
-
async function reportAgentFailure(apiKey, agentType, errorCode) {
|
|
1920
|
+
async function reportAgentFailure(apiKey, agentType, errorCode, baseUrl = ROUTING_API_BASE_URL2) {
|
|
1921
1921
|
try {
|
|
1922
|
-
await fetch(`${
|
|
1922
|
+
await fetch(`${baseUrl}/api/v1/agent/health-report`, {
|
|
1923
1923
|
method: "POST",
|
|
1924
1924
|
headers: {
|
|
1925
1925
|
"Content-Type": "application/json",
|
|
@@ -1938,12 +1938,12 @@ async function reportAgentFailure(apiKey, agentType, errorCode) {
|
|
|
1938
1938
|
);
|
|
1939
1939
|
}
|
|
1940
1940
|
}
|
|
1941
|
-
async function withFailureReporting(apiKey, agentType, fn) {
|
|
1941
|
+
async function withFailureReporting(apiKey, agentType, fn, baseUrl) {
|
|
1942
1942
|
try {
|
|
1943
1943
|
return await fn();
|
|
1944
1944
|
} catch (err) {
|
|
1945
1945
|
const errorCode = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
|
|
1946
|
-
void reportAgentFailure(apiKey, agentType, errorCode);
|
|
1946
|
+
void reportAgentFailure(apiKey, agentType, errorCode, baseUrl);
|
|
1947
1947
|
throw err;
|
|
1948
1948
|
}
|
|
1949
1949
|
}
|
|
@@ -2848,7 +2848,10 @@ var OwneySDK = class {
|
|
|
2848
2848
|
async getOrgAgentConfig() {
|
|
2849
2849
|
if (this.orgAgentConfig !== void 0) return this.orgAgentConfig;
|
|
2850
2850
|
if (!this.orgAgentConfigPromise) {
|
|
2851
|
-
this.orgAgentConfigPromise = fetchOrgAgentConfig(
|
|
2851
|
+
this.orgAgentConfigPromise = fetchOrgAgentConfig(
|
|
2852
|
+
this.apiKey,
|
|
2853
|
+
this.routingApiBaseUrl
|
|
2854
|
+
).then(
|
|
2852
2855
|
(config) => {
|
|
2853
2856
|
this.orgAgentConfig = config;
|
|
2854
2857
|
return config;
|
|
@@ -2888,7 +2891,10 @@ var OwneySDK = class {
|
|
|
2888
2891
|
if (this.agents.size > 0) return;
|
|
2889
2892
|
if (!this.initializingAgentsPromise) {
|
|
2890
2893
|
this.initializingAgentsPromise = (async () => {
|
|
2891
|
-
const agentKeys = await fetchAgentKeys(
|
|
2894
|
+
const agentKeys = await fetchAgentKeys(
|
|
2895
|
+
this.apiKey,
|
|
2896
|
+
this.routingApiBaseUrl
|
|
2897
|
+
);
|
|
2892
2898
|
this.disabledAgents.clear();
|
|
2893
2899
|
for (const { key: key2, agent_type, is_enabled } of agentKeys) {
|
|
2894
2900
|
const agent = this.createAgent(agent_type, key2);
|
|
@@ -3144,7 +3150,8 @@ var OwneySDK = class {
|
|
|
3144
3150
|
amount,
|
|
3145
3151
|
asset,
|
|
3146
3152
|
callback
|
|
3147
|
-
)
|
|
3153
|
+
),
|
|
3154
|
+
this.routingApiBaseUrl
|
|
3148
3155
|
);
|
|
3149
3156
|
let approvalAttempted = false;
|
|
3150
3157
|
for (; ; ) {
|
|
@@ -3294,7 +3301,8 @@ var OwneySDK = class {
|
|
|
3294
3301
|
return withFailureReporting(
|
|
3295
3302
|
this.apiKey,
|
|
3296
3303
|
agent.id,
|
|
3297
|
-
() => agent.withdraw(state, chainId, token, amount)
|
|
3304
|
+
() => agent.withdraw(state, chainId, token, amount),
|
|
3305
|
+
this.routingApiBaseUrl
|
|
3298
3306
|
);
|
|
3299
3307
|
}
|
|
3300
3308
|
const eligibleAgents = this.getEligibleAgents(chainId, asset);
|
|
@@ -3308,7 +3316,12 @@ var OwneySDK = class {
|
|
|
3308
3316
|
console.error(`withdraw failed for agent "${agent.id}":`, err);
|
|
3309
3317
|
agentErrors2[agent.id] = err instanceof Error ? err.message : String(err);
|
|
3310
3318
|
const code = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
|
|
3311
|
-
void reportAgentFailure(
|
|
3319
|
+
void reportAgentFailure(
|
|
3320
|
+
this.apiKey,
|
|
3321
|
+
agent.id,
|
|
3322
|
+
code,
|
|
3323
|
+
this.routingApiBaseUrl
|
|
3324
|
+
);
|
|
3312
3325
|
}
|
|
3313
3326
|
}
|
|
3314
3327
|
if (Object.keys(results2).length === 0) {
|
|
@@ -3377,7 +3390,12 @@ var OwneySDK = class {
|
|
|
3377
3390
|
console.error(`withdraw failed for agent "${p.agent.id}":`, err);
|
|
3378
3391
|
agentErrors[p.agent.id] = err instanceof Error ? err.message : String(err);
|
|
3379
3392
|
const code = err instanceof OwneyError ? err.code : "SDK_AGENT_FAILURE";
|
|
3380
|
-
void reportAgentFailure(
|
|
3393
|
+
void reportAgentFailure(
|
|
3394
|
+
this.apiKey,
|
|
3395
|
+
p.agent.id,
|
|
3396
|
+
code,
|
|
3397
|
+
this.routingApiBaseUrl
|
|
3398
|
+
);
|
|
3381
3399
|
const failedAmount = p.planned;
|
|
3382
3400
|
p.planned = 0n;
|
|
3383
3401
|
redistributeShare(plans, i, failedAmount);
|