@sandbank.dev/cloud 0.1.0 → 0.1.1
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/adapter.d.ts.map +1 -1
- package/dist/adapter.js +7 -9
- package/dist/x402-fetch.d.ts.map +1 -1
- package/dist/x402-fetch.js +19 -4
- package/package.json +2 -2
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,YAAY,EAGZ,UAAU,EACV,cAAc,EACd,WAAW,EAEZ,MAAM,oBAAoB,CAAA;AAG3B,OAAO,KAAK,EAAE,mBAAmB,EAA6B,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,YAAY,EAGZ,UAAU,EACV,cAAc,EACd,WAAW,EAEZ,MAAM,oBAAoB,CAAA;AAG3B,OAAO,KAAK,EAAE,mBAAmB,EAA6B,MAAM,YAAY,CAAA;AAgIhF,qBAAa,oBAAqB,YAAW,cAAc;IACzD,QAAQ,CAAC,IAAI,oBAAmB;IAChC,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC,UAAU,CAAC,CAG5C;IAEF,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAoC;gBAE5C,MAAM,GAAE,mBAAwB;IAItC,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IAuB5D,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAU/C,aAAa,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAqB1D,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQhD"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { SandboxNotFoundError, ProviderError } from '@sandbank.dev/core';
|
|
2
2
|
import { createX402Fetch } from './x402-fetch.js';
|
|
3
|
+
const KNOWN_STATES = new Set(['creating', 'running', 'stopped', 'error', 'terminated']);
|
|
3
4
|
function mapState(status) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
default:
|
|
11
|
-
return 'error';
|
|
12
|
-
}
|
|
5
|
+
if (status === 'terminated')
|
|
6
|
+
return 'stopped';
|
|
7
|
+
if (KNOWN_STATES.has(status))
|
|
8
|
+
return status;
|
|
9
|
+
// Unknown states (e.g. future "paused") — pass through as-is, let core handle it
|
|
10
|
+
return status;
|
|
13
11
|
}
|
|
14
12
|
function isNotFound(err) {
|
|
15
13
|
const msg = err instanceof Error ? err.message : String(err);
|
package/dist/x402-fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"x402-fetch.d.ts","sourceRoot":"","sources":["../src/x402-fetch.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,mBAAmB;gBAgBhC,CAAC,QAClB,MAAM,YACH,WAAW,KACnB,OAAO,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"x402-fetch.d.ts","sourceRoot":"","sources":["../src/x402-fetch.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,mBAAmB;gBAgBhC,CAAC,QAClB,MAAM,YACH,WAAW,KACnB,OAAO,CAAC,CAAC,CAAC;yBA2EL,MAAM,YACH,WAAW,KACnB,OAAO,CAAC,QAAQ,CAAC;;EAgBrB"}
|
package/dist/x402-fetch.js
CHANGED
|
@@ -35,7 +35,7 @@ export function createX402Fetch(config) {
|
|
|
35
35
|
// Handle x402 payment
|
|
36
36
|
if (response.status === 402 && httpClient) {
|
|
37
37
|
const paymentRequired = httpClient.getPaymentRequiredResponse((name) => response.headers.get(name), await response.clone().json().catch(() => undefined));
|
|
38
|
-
// Try hooks first (e.g., cached tokens)
|
|
38
|
+
// Try hooks first (e.g., cached tokens) — if they succeed, return; if not, fall through to payment
|
|
39
39
|
const hookHeaders = await httpClient.handlePaymentRequired(paymentRequired);
|
|
40
40
|
if (hookHeaders) {
|
|
41
41
|
const retryResp = await fetch(url, {
|
|
@@ -44,8 +44,13 @@ export function createX402Fetch(config) {
|
|
|
44
44
|
});
|
|
45
45
|
if (retryResp.ok) {
|
|
46
46
|
const text = await retryResp.text();
|
|
47
|
-
|
|
47
|
+
if (!text)
|
|
48
|
+
throw new Error('Sandbank Cloud: empty response after x402 payment');
|
|
49
|
+
return JSON.parse(text);
|
|
48
50
|
}
|
|
51
|
+
// Hook payment was rejected — don't create a second payment, throw immediately
|
|
52
|
+
const body = await retryResp.text();
|
|
53
|
+
throw new Error(`Sandbank Cloud API error ${retryResp.status} (after hook payment): ${body}`);
|
|
49
54
|
}
|
|
50
55
|
// Create payment payload and retry
|
|
51
56
|
const paymentPayload = await httpClient.createPaymentPayload(paymentRequired);
|
|
@@ -59,7 +64,9 @@ export function createX402Fetch(config) {
|
|
|
59
64
|
throw new Error(`Sandbank Cloud API error ${paidResponse.status}: ${body}`);
|
|
60
65
|
}
|
|
61
66
|
const text = await paidResponse.text();
|
|
62
|
-
|
|
67
|
+
if (!text)
|
|
68
|
+
throw new Error('Sandbank Cloud: empty response after x402 payment');
|
|
69
|
+
return JSON.parse(text);
|
|
63
70
|
}
|
|
64
71
|
if (response.status === 402) {
|
|
65
72
|
throw new Error('Sandbank Cloud: HTTP 402 Payment Required — provide walletPrivateKey for x402 payment or apiToken for authenticated access');
|
|
@@ -69,7 +76,11 @@ export function createX402Fetch(config) {
|
|
|
69
76
|
throw new Error(`Sandbank Cloud API error ${response.status}: ${body}`);
|
|
70
77
|
}
|
|
71
78
|
const text = await response.text();
|
|
72
|
-
|
|
79
|
+
if (!text) {
|
|
80
|
+
// Only DELETE returns empty bodies legitimately
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
return JSON.parse(text);
|
|
73
84
|
}
|
|
74
85
|
async function x402FetchRaw(path, options = {}) {
|
|
75
86
|
const url = `${baseUrl}/v1${path}`;
|
|
@@ -79,6 +90,10 @@ export function createX402Fetch(config) {
|
|
|
79
90
|
if (apiToken) {
|
|
80
91
|
headers['Authorization'] = `Bearer ${apiToken}`;
|
|
81
92
|
}
|
|
93
|
+
// Default to JSON content type if body is present and no Content-Type set
|
|
94
|
+
if (options.body && !headers['Content-Type']) {
|
|
95
|
+
headers['Content-Type'] = 'application/json';
|
|
96
|
+
}
|
|
82
97
|
return fetch(url, { ...options, headers });
|
|
83
98
|
}
|
|
84
99
|
return { x402Fetch, x402FetchRaw, baseUrl };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sandbank.dev/cloud",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Sandbank Cloud adapter with x402 payment support",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"clean": "rm -rf dist"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@sandbank.dev/core": "
|
|
37
|
+
"@sandbank.dev/core": "^0.3.4",
|
|
38
38
|
"@x402/core": "^2.6.0",
|
|
39
39
|
"@x402/evm": "^2.6.0",
|
|
40
40
|
"viem": "^2.0.0"
|