faucet-server-app 0.0.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/LICENSE +661 -0
- package/README.md +3 -0
- package/dist/esm/api/captcha.d.ts +38 -0
- package/dist/esm/api/captcha.d.ts.map +1 -0
- package/dist/esm/api/captcha.js +44 -0
- package/dist/esm/api/captcha.js.map +1 -0
- package/dist/esm/api/claim.d.ts +2 -0
- package/dist/esm/api/claim.d.ts.map +1 -0
- package/dist/esm/api/claim.js +2 -0
- package/dist/esm/api/claim.js.map +1 -0
- package/dist/esm/api/dummy.d.ts +28 -0
- package/dist/esm/api/dummy.d.ts.map +1 -0
- package/dist/esm/api/dummy.js +17 -0
- package/dist/esm/api/dummy.js.map +1 -0
- package/dist/esm/api/index.d.ts +41 -0
- package/dist/esm/api/index.d.ts.map +1 -0
- package/dist/esm/api/index.js +122 -0
- package/dist/esm/api/index.js.map +1 -0
- package/dist/esm/env.d.ts +8 -0
- package/dist/esm/env.d.ts.map +1 -0
- package/dist/esm/env.js +2 -0
- package/dist/esm/env.js.map +1 -0
- package/dist/esm/index.d.ts +82 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +53 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/schema/ts/db.sql.d.ts +3 -0
- package/dist/esm/schema/ts/db.sql.d.ts.map +1 -0
- package/dist/esm/schema/ts/db.sql.js +7 -0
- package/dist/esm/schema/ts/db.sql.js.map +1 -0
- package/dist/esm/setup.d.ts +16 -0
- package/dist/esm/setup.d.ts.map +1 -0
- package/dist/esm/setup.js +19 -0
- package/dist/esm/setup.js.map +1 -0
- package/dist/esm/types.d.ts +12 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +44 -0
- package/src/api/index.ts +179 -0
- package/src/env.ts +9 -0
- package/src/index.ts +72 -0
- package/src/schema/sql/db.sql +5 -0
- package/src/schema/ts/db.sql.ts +6 -0
- package/src/setup.ts +45 -0
- package/src/types.ts +8 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ServerOptions } from '../types.js';
|
|
2
|
+
import { Env } from '../env.js';
|
|
3
|
+
export declare function getCaptchaAPI<CustomEnv extends Env>(options: ServerOptions<CustomEnv>): import("hono/hono-base").HonoBase<import("hono/utils/types").IfAnyThenEmptyObject<{
|
|
4
|
+
Bindings: CustomEnv;
|
|
5
|
+
} extends infer T ? T extends {
|
|
6
|
+
Bindings: CustomEnv;
|
|
7
|
+
} ? T extends import("hono").Env ? import("hono").Env extends T ? {} : T : T : never : never> & {}, {
|
|
8
|
+
"/verify": {
|
|
9
|
+
$post: {
|
|
10
|
+
input: {};
|
|
11
|
+
output: "hello world";
|
|
12
|
+
outputFormat: "text";
|
|
13
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
14
|
+
} | {
|
|
15
|
+
input: {};
|
|
16
|
+
output: {
|
|
17
|
+
error: string;
|
|
18
|
+
};
|
|
19
|
+
outputFormat: "json";
|
|
20
|
+
status: 500;
|
|
21
|
+
} | {
|
|
22
|
+
input: {};
|
|
23
|
+
output: {
|
|
24
|
+
error: string;
|
|
25
|
+
};
|
|
26
|
+
outputFormat: "json";
|
|
27
|
+
status: 400;
|
|
28
|
+
} | {
|
|
29
|
+
input: {};
|
|
30
|
+
output: {
|
|
31
|
+
error: string;
|
|
32
|
+
};
|
|
33
|
+
outputFormat: "json";
|
|
34
|
+
status: 401;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}, "/", "/verify">;
|
|
38
|
+
//# sourceMappingURL=captcha.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captcha.d.ts","sourceRoot":"","sources":["../../../src/api/captcha.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAC,GAAG,EAAC,MAAM,WAAW,CAAC;AA8B9B,wBAAgB,aAAa,CAAC,SAAS,SAAS,GAAG,EAClD,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC;cAED,SAAS;;cAAT,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA4BzC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { setup } from '../setup.js';
|
|
3
|
+
const PROSOPO_VERIFY_ENDPOINT = 'https://api.prosopo.io/siteverify';
|
|
4
|
+
async function verifyProsopoCaptcha(token, secret) {
|
|
5
|
+
const body = {
|
|
6
|
+
token,
|
|
7
|
+
secret,
|
|
8
|
+
};
|
|
9
|
+
const response = await fetch(PROSOPO_VERIFY_ENDPOINT, {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
headers: {
|
|
12
|
+
'Content-Type': 'application/json',
|
|
13
|
+
},
|
|
14
|
+
body: JSON.stringify(body),
|
|
15
|
+
});
|
|
16
|
+
const result = (await response.json());
|
|
17
|
+
return result.verified === true;
|
|
18
|
+
}
|
|
19
|
+
export function getCaptchaAPI(options) {
|
|
20
|
+
const app = new Hono()
|
|
21
|
+
.use(setup({ serverOptions: options }))
|
|
22
|
+
.post('/verify', async (c) => {
|
|
23
|
+
const config = c.get('config');
|
|
24
|
+
const env = config.env;
|
|
25
|
+
const secret = env.PROSOPO_SITE_PRIVATE_KEY;
|
|
26
|
+
if (!secret) {
|
|
27
|
+
return c.json({ error: 'PROSOPO_SITE_PRIVATE_KEY not configured' }, 500);
|
|
28
|
+
}
|
|
29
|
+
const body = await c.req.json();
|
|
30
|
+
const token = body.token;
|
|
31
|
+
if (!token) {
|
|
32
|
+
return c.json({ error: 'Missing token' }, 400);
|
|
33
|
+
}
|
|
34
|
+
const verified = await verifyProsopoCaptcha(token, secret);
|
|
35
|
+
if (verified) {
|
|
36
|
+
return c.text('hello world');
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return c.json({ error: 'Captcha verification failed' }, 401);
|
|
40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C,EAAC,KAAK,EAAE,yCAAyC,EAAC,EAAE,GAAG,CAAC,CAAC;QACxE,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,EAAmB,CAAC;QACjD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAEzB,IAAI,CAAC,KAAK,EAAE,CAAC;YACZ,OAAO,CAAC,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,eAAe,EAAC,EAAE,GAAG,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAE3D,IAAI,QAAQ,EAAE,CAAC;YACd,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACP,OAAO,CAAC,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,6BAA6B,EAAC,EAAE,GAAG,CAAC,CAAC;QAC5D,CAAC;IACF,CAAC,CAAC,CAAC;IAEJ,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim.d.ts","sourceRoot":"","sources":["../../../src/api/claim.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim.js","sourceRoot":"","sources":["../../../src/api/claim.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ServerOptions } from '../types.js';
|
|
2
|
+
import { Env } from '../env.js';
|
|
3
|
+
export declare function getDummyAPI<CustomEnv extends Env>(options: ServerOptions<CustomEnv>): import("hono/hono-base").HonoBase<import("hono/utils/types").IfAnyThenEmptyObject<{
|
|
4
|
+
Bindings: CustomEnv;
|
|
5
|
+
} extends infer T ? T extends {
|
|
6
|
+
Bindings: CustomEnv;
|
|
7
|
+
} ? T extends import("hono").Env ? import("hono").Env extends T ? {} : T : T : never : never> & {}, {
|
|
8
|
+
"/": {
|
|
9
|
+
$get: {
|
|
10
|
+
input: {};
|
|
11
|
+
output: "hello world";
|
|
12
|
+
outputFormat: "text";
|
|
13
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
} & {
|
|
17
|
+
"/setup": {
|
|
18
|
+
$get: {
|
|
19
|
+
input: {};
|
|
20
|
+
output: {
|
|
21
|
+
success: true;
|
|
22
|
+
};
|
|
23
|
+
outputFormat: "json";
|
|
24
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}, "/", "/setup">;
|
|
28
|
+
//# sourceMappingURL=dummy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dummy.d.ts","sourceRoot":"","sources":["../../../src/api/dummy.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAC,GAAG,EAAC,MAAM,WAAW,CAAC;AAE9B,wBAAgB,WAAW,CAAC,SAAS,SAAS,GAAG,EAChD,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC;cAED,SAAS;;cAAT,SAAS;;;;;;;;;;;;;;;;;;;;;kBAazC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { setup } from '../setup.js';
|
|
3
|
+
export function getDummyAPI(options) {
|
|
4
|
+
const app = new Hono()
|
|
5
|
+
.use(setup({ serverOptions: options }))
|
|
6
|
+
.get('/', async (c) => {
|
|
7
|
+
const config = c.get('config');
|
|
8
|
+
const env = config.env;
|
|
9
|
+
// const storage = config.storage;
|
|
10
|
+
return c.text('hello world');
|
|
11
|
+
})
|
|
12
|
+
.get('/setup', async (c) => {
|
|
13
|
+
return c.json({ success: true });
|
|
14
|
+
});
|
|
15
|
+
return app;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=dummy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dummy.js","sourceRoot":"","sources":["../../../src/api/dummy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAE1B,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAC;AAGlC,MAAM,UAAU,WAAW,CAC1B,OAAiC;IAEjC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAyB;SAC3C,GAAG,CAAC,KAAK,CAAC,EAAC,aAAa,EAAE,OAAO,EAAC,CAAC,CAAC;SACpC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QACrB,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACvB,kCAAkC;QAClC,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC9B,CAAC,CAAC;SACD,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QAC1B,OAAO,CAAC,CAAC,IAAI,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEJ,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ServerOptions } from '../types.js';
|
|
2
|
+
import { Env } from '../env.js';
|
|
3
|
+
export declare function getAPI<CustomEnv extends Env>(options: ServerOptions<CustomEnv>): import("hono/hono-base").HonoBase<import("hono/utils/types").IfAnyThenEmptyObject<{
|
|
4
|
+
Bindings: CustomEnv;
|
|
5
|
+
} extends infer T ? T extends {
|
|
6
|
+
Bindings: CustomEnv;
|
|
7
|
+
} ? T extends import("hono").Env ? import("hono").Env extends T ? {} : T : T : never : never> & {}, {
|
|
8
|
+
"/claim": {
|
|
9
|
+
$post: {
|
|
10
|
+
input: {};
|
|
11
|
+
output: {
|
|
12
|
+
error: string;
|
|
13
|
+
};
|
|
14
|
+
outputFormat: "json";
|
|
15
|
+
status: 500;
|
|
16
|
+
} | {
|
|
17
|
+
input: {};
|
|
18
|
+
output: {
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
21
|
+
outputFormat: "json";
|
|
22
|
+
status: 400;
|
|
23
|
+
} | {
|
|
24
|
+
input: {};
|
|
25
|
+
output: {
|
|
26
|
+
error: string;
|
|
27
|
+
};
|
|
28
|
+
outputFormat: "json";
|
|
29
|
+
status: 401;
|
|
30
|
+
} | {
|
|
31
|
+
input: {};
|
|
32
|
+
output: {
|
|
33
|
+
success: true;
|
|
34
|
+
txHash: `0x${string}`;
|
|
35
|
+
};
|
|
36
|
+
outputFormat: "json";
|
|
37
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}, "/", "/claim">;
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAC,GAAG,EAAC,MAAM,WAAW,CAAC;AA6D9B,wBAAgB,MAAM,CAAC,SAAS,SAAS,GAAG,EAC3C,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC;cAED,SAAS;;cAAT,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA+GzC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { setup } from '../setup.js';
|
|
3
|
+
import { createWalletClient, http, isAddress, } from 'viem';
|
|
4
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
5
|
+
const PROSOPO_VERIFY_ENDPOINT = 'https://api.prosopo.io/siteverify';
|
|
6
|
+
async function verifyProsopoCaptcha(token, secret) {
|
|
7
|
+
const body = {
|
|
8
|
+
token,
|
|
9
|
+
secret,
|
|
10
|
+
};
|
|
11
|
+
const response = await fetch(PROSOPO_VERIFY_ENDPOINT, {
|
|
12
|
+
method: 'POST',
|
|
13
|
+
headers: {
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
},
|
|
16
|
+
body: JSON.stringify(body),
|
|
17
|
+
});
|
|
18
|
+
const result = (await response.json());
|
|
19
|
+
return result.verified === true;
|
|
20
|
+
}
|
|
21
|
+
function parseChainConfig(configValue) {
|
|
22
|
+
// Format: <amount>:<rpc_endpoint>
|
|
23
|
+
const colonIndex = configValue.indexOf(':');
|
|
24
|
+
if (colonIndex === -1) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const amount = configValue.substring(0, colonIndex);
|
|
28
|
+
const rpcUrl = configValue.substring(colonIndex + 1);
|
|
29
|
+
if (!amount || !rpcUrl) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return { amount, rpcUrl };
|
|
33
|
+
}
|
|
34
|
+
export function getAPI(options) {
|
|
35
|
+
const app = new Hono()
|
|
36
|
+
.use(setup({ serverOptions: options }))
|
|
37
|
+
.post('/claim', async (c) => {
|
|
38
|
+
const config = c.get('config');
|
|
39
|
+
const env = config.env;
|
|
40
|
+
// Check if captcha is disabled (for localhost development)
|
|
41
|
+
const captchaDisabled = env.DISABLE_CAPTCHA === 'true';
|
|
42
|
+
// Validate PROSOPO secret (only required if captcha is enabled)
|
|
43
|
+
const secret = env.PROSOPO_SITE_PRIVATE_KEY;
|
|
44
|
+
if (!captchaDisabled && !secret) {
|
|
45
|
+
return c.json({ error: 'PROSOPO_SITE_PRIVATE_KEY not configured' }, 500);
|
|
46
|
+
}
|
|
47
|
+
// Validate FAUCET_PRIVATE_KEY
|
|
48
|
+
const faucetPrivateKey = env.FAUCET_PRIVATE_KEY;
|
|
49
|
+
if (!faucetPrivateKey) {
|
|
50
|
+
return c.json({ error: 'FAUCET_PRIVATE_KEY not configured' }, 500);
|
|
51
|
+
}
|
|
52
|
+
const body = await c.req.json();
|
|
53
|
+
const { token, chainId, address } = body;
|
|
54
|
+
// Validate required fields
|
|
55
|
+
if (!token) {
|
|
56
|
+
return c.json({ error: 'Missing token' }, 400);
|
|
57
|
+
}
|
|
58
|
+
if (!chainId) {
|
|
59
|
+
return c.json({ error: 'Missing chainId' }, 400);
|
|
60
|
+
}
|
|
61
|
+
if (!address) {
|
|
62
|
+
return c.json({ error: 'Missing address' }, 400);
|
|
63
|
+
}
|
|
64
|
+
// Validate address format
|
|
65
|
+
if (!isAddress(address)) {
|
|
66
|
+
return c.json({ error: 'Invalid Ethereum address' }, 400);
|
|
67
|
+
}
|
|
68
|
+
// Parse chainId
|
|
69
|
+
const chainIdNum = parseInt(chainId, 10);
|
|
70
|
+
if (isNaN(chainIdNum) || chainIdNum <= 0) {
|
|
71
|
+
return c.json({ error: 'Invalid chainId' }, 400);
|
|
72
|
+
}
|
|
73
|
+
// Check for chain-specific config (format: <amount>:<rpc_endpoint>)
|
|
74
|
+
const chainConfigKey = `CHAIN_${chainId}`;
|
|
75
|
+
const chainConfigValue = env[chainConfigKey];
|
|
76
|
+
if (!chainConfigValue) {
|
|
77
|
+
return c.json({ error: `Faucet not configured for chain ${chainId}` }, 400);
|
|
78
|
+
}
|
|
79
|
+
const chainConfig = parseChainConfig(chainConfigValue);
|
|
80
|
+
if (!chainConfig) {
|
|
81
|
+
return c.json({
|
|
82
|
+
error: `Invalid chain config format for chain ${chainId}. Expected: <amount>:<rpc_endpoint>`,
|
|
83
|
+
}, 500);
|
|
84
|
+
}
|
|
85
|
+
// Verify captcha (skip if disabled for localhost development)
|
|
86
|
+
if (!captchaDisabled) {
|
|
87
|
+
const verified = await verifyProsopoCaptcha(token, secret);
|
|
88
|
+
if (!verified) {
|
|
89
|
+
return c.json({ error: 'Captcha verification failed' }, 401);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
// Create wallet client and send transaction
|
|
94
|
+
const account = privateKeyToAccount(faucetPrivateKey);
|
|
95
|
+
const { amount, rpcUrl } = chainConfig;
|
|
96
|
+
const walletClient = createWalletClient({
|
|
97
|
+
account,
|
|
98
|
+
chain: {
|
|
99
|
+
id: chainIdNum,
|
|
100
|
+
name: `Chain ${chainIdNum}`,
|
|
101
|
+
nativeCurrency: { name: 'ETH', symbol: 'ETH', decimals: 18 },
|
|
102
|
+
rpcUrls: {
|
|
103
|
+
default: { http: [rpcUrl] },
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
transport: http(rpcUrl),
|
|
107
|
+
});
|
|
108
|
+
const txHash = await walletClient.sendTransaction({
|
|
109
|
+
to: address,
|
|
110
|
+
value: BigInt(amount),
|
|
111
|
+
});
|
|
112
|
+
return c.json({ success: true, txHash });
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
console.error('Transaction error:', err);
|
|
116
|
+
const errorMessage = err instanceof Error ? err.message : 'Transaction failed';
|
|
117
|
+
return c.json({ error: errorMessage }, 500);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
return app;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAE1B,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAC;AAElC,OAAO,EACN,kBAAkB,EAClB,IAAI,EACJ,SAAS,GAIT,MAAM,MAAM,CAAC;AACd,OAAO,EAAC,mBAAmB,EAAC,MAAM,eAAe,CAAC;AAElD,MAAM,uBAAuB,GAAG,mCAAmC,CAAC;AAapE,KAAK,UAAU,oBAAoB,CAClC,KAAa,EACb,MAAc;IAEd,MAAM,IAAI,GAAG;QACZ,KAAK;QACL,MAAM;KACN,CA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AM,EAAE,GAAG,MAAM,GAAG,SAAS,CAAC;CAC7C,CAAC"}
|
package/dist/esm/env.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/env.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ServerOptions } from './types.js';
|
|
2
|
+
import { hc } from 'hono/client';
|
|
3
|
+
import { Env } from './env.js';
|
|
4
|
+
export type { Env };
|
|
5
|
+
export declare function createServer<CustomEnv extends Env>(options: ServerOptions<CustomEnv>): import("hono/hono-base").HonoBase<import("hono/utils/types").IfAnyThenEmptyObject<{
|
|
6
|
+
Bindings: CustomEnv;
|
|
7
|
+
} extends infer T ? T extends {
|
|
8
|
+
Bindings: CustomEnv;
|
|
9
|
+
} ? T extends import("hono").Env ? import("hono").Env extends T ? {} : T : T : never : never> & {}, import("hono/types").BlankSchema | import("hono/types").MergeSchemaPath<{
|
|
10
|
+
"/claim": {
|
|
11
|
+
$post: {
|
|
12
|
+
input: {};
|
|
13
|
+
output: {
|
|
14
|
+
error: string;
|
|
15
|
+
};
|
|
16
|
+
outputFormat: "json";
|
|
17
|
+
status: 500;
|
|
18
|
+
} | {
|
|
19
|
+
input: {};
|
|
20
|
+
output: {
|
|
21
|
+
error: string;
|
|
22
|
+
};
|
|
23
|
+
outputFormat: "json";
|
|
24
|
+
status: 400;
|
|
25
|
+
} | {
|
|
26
|
+
input: {};
|
|
27
|
+
output: {
|
|
28
|
+
error: string;
|
|
29
|
+
};
|
|
30
|
+
outputFormat: "json";
|
|
31
|
+
status: 401;
|
|
32
|
+
} | {
|
|
33
|
+
input: {};
|
|
34
|
+
output: {
|
|
35
|
+
success: true;
|
|
36
|
+
txHash: `0x${string}`;
|
|
37
|
+
};
|
|
38
|
+
outputFormat: "json";
|
|
39
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
}, "/api/">, "/", "/api/*">;
|
|
43
|
+
export type App = ReturnType<typeof createServer>;
|
|
44
|
+
declare const client: {
|
|
45
|
+
api: {
|
|
46
|
+
claim: import("hono/client").ClientRequest<string, "/api/claim", {
|
|
47
|
+
$post: {
|
|
48
|
+
input: {};
|
|
49
|
+
output: {
|
|
50
|
+
error: string;
|
|
51
|
+
};
|
|
52
|
+
outputFormat: "json";
|
|
53
|
+
status: 500;
|
|
54
|
+
} | {
|
|
55
|
+
input: {};
|
|
56
|
+
output: {
|
|
57
|
+
error: string;
|
|
58
|
+
};
|
|
59
|
+
outputFormat: "json";
|
|
60
|
+
status: 400;
|
|
61
|
+
} | {
|
|
62
|
+
input: {};
|
|
63
|
+
output: {
|
|
64
|
+
error: string;
|
|
65
|
+
};
|
|
66
|
+
outputFormat: "json";
|
|
67
|
+
status: 401;
|
|
68
|
+
} | {
|
|
69
|
+
input: {};
|
|
70
|
+
output: {
|
|
71
|
+
success: true;
|
|
72
|
+
txHash: `0x${string}`;
|
|
73
|
+
};
|
|
74
|
+
outputFormat: "json";
|
|
75
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
76
|
+
};
|
|
77
|
+
}>;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
export type Client = typeof client;
|
|
81
|
+
export declare const createClient: (...args: Parameters<typeof hc>) => Client;
|
|
82
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,EAAE,EAAC,MAAM,aAAa,CAAC;AAE/B,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAC;AAG7B,YAAY,EAAC,GAAG,EAAC,CAAC;AAkBlB,wBAAgB,YAAY,CAAC,SAAS,SAAS,GAAG,EACjD,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC;cAED,SAAS;;cAAT,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAkCzC;AAED,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAGlD,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAc,CAAC;AAC3B,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC;AACnC,eAAO,MAAM,YAAY,GAAI,GAAG,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC,KAAG,MAC7C,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { cors } from 'hono/cors';
|
|
3
|
+
import { hc } from 'hono/client';
|
|
4
|
+
import { HTTPException } from 'hono/http-exception';
|
|
5
|
+
import { getAPI } from './api/index.js';
|
|
6
|
+
// export type {Storage} from './storage/index.js';
|
|
7
|
+
const corsSetup = cors({
|
|
8
|
+
origin: '*',
|
|
9
|
+
allowHeaders: [
|
|
10
|
+
'X-Custom-Header',
|
|
11
|
+
'Upgrade-Insecure-Requests',
|
|
12
|
+
'Content-Type',
|
|
13
|
+
'SIGNATURE',
|
|
14
|
+
],
|
|
15
|
+
allowMethods: ['POST', 'GET', 'HEAD', 'OPTIONS'],
|
|
16
|
+
exposeHeaders: ['Content-Length', 'X-Kuma-Revision'],
|
|
17
|
+
maxAge: 600,
|
|
18
|
+
credentials: true,
|
|
19
|
+
});
|
|
20
|
+
export function createServer(options) {
|
|
21
|
+
const app = new Hono();
|
|
22
|
+
const api = getAPI(options);
|
|
23
|
+
return app
|
|
24
|
+
.use('/api/*', corsSetup)
|
|
25
|
+
.route('/api/', api)
|
|
26
|
+
.onError((err, c) => {
|
|
27
|
+
const config = c.get('config');
|
|
28
|
+
const env = config?.env || {};
|
|
29
|
+
console.error(err);
|
|
30
|
+
if (err instanceof HTTPException) {
|
|
31
|
+
if (err.res) {
|
|
32
|
+
return err.getResponse();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return c.json({
|
|
36
|
+
success: false,
|
|
37
|
+
errors: [
|
|
38
|
+
{
|
|
39
|
+
name: 'name' in err ? err.name : undefined,
|
|
40
|
+
code: 'code' in err ? err.code : 5000,
|
|
41
|
+
status: 'status' in err ? err.status : undefined,
|
|
42
|
+
message: err.message,
|
|
43
|
+
cause: env.DEV ? err.cause : undefined,
|
|
44
|
+
stack: env.DEV ? err.stack : undefined,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
}, 500);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
// this is a trick to calculate the type when compiling
|
|
51
|
+
const client = hc('');
|
|
52
|
+
export const createClient = (...args) => hc(...args);
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAE/B,OAAO,EAAC,EAAE,EAAC,MAAM,aAAa,CAAC;AAC/B,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAC,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAItC,mDAAmD;AAEnD,MAAM,SAAS,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,GAAG;IACX,YAAY,EAAE;QACb,iBAAiB;QACjB,2BAA2B;QAC3B,cAAc;QACd,WAAW;KACX;IACD,YAAY,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC;IAChD,aAAa,EAAE,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;IACpD,MAAM,EAAE,GAAG;IACX,WAAW,EAAE,IAAI;CACjB,CAAC,CAAC;AAEH,MAAM,UAAU,YAAY,CAC3B,OAAiC;IAEjC,MAAM,GAAG,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C,CAAC;AACL,CAAC;AAID,uDAAuD;AACvD,MAAM,MAAM,GAAG,EAAE,CAAM,EAAE,CAAC,CAAC;AAE3B,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAG,IAA2B,EAAU,EAAE,CACtE,EAAE,CAAM,GAAG,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.sql.d.ts","sourceRoot":"","sources":["../../../../src/schema/ts/db.sql.ts"],"names":[],"mappings":";AAAA,wBAKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.sql.js","sourceRoot":"","sources":["../../../../src/schema/ts/db.sql.ts"],"names":[],"mappings":"AAAA,eAAe;;;;;CAKd,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MiddlewareHandler } from 'hono/types';
|
|
2
|
+
import { ServerOptions } from './types.js';
|
|
3
|
+
import { Env } from './env.js';
|
|
4
|
+
export type SetupOptions<CustomEnv extends Env> = {
|
|
5
|
+
serverOptions: ServerOptions<CustomEnv>;
|
|
6
|
+
};
|
|
7
|
+
export type Config<CustomEnv extends Env> = {
|
|
8
|
+
env: CustomEnv;
|
|
9
|
+
};
|
|
10
|
+
declare module 'hono' {
|
|
11
|
+
interface ContextVariableMap {
|
|
12
|
+
config: Config<Env>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export declare function setup<CustomEnv extends Env>(options: SetupOptions<CustomEnv>): MiddlewareHandler;
|
|
16
|
+
//# sourceMappingURL=setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAC;AAG7B,MAAM,MAAM,YAAY,CAAC,SAAS,SAAS,GAAG,IAAI;IACjD,aAAa,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,SAAS,SAAS,GAAG,IAAI;IAE3C,GAAG,EAAE,SAAS,CAAC;CACf,CAAC;AAEF,OAAO,QAAQ,MAAM,CAAC;IACrB,UAAU,kBAAkB;QAC3B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;KACpB;CACD;AAED,wBAAgB,KAAK,CAAC,SAAS,SAAS,GAAG,EAC1C,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,GAC9B,iBAAiB,CAsBnB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function setup(options) {
|
|
2
|
+
const { getDB, getEnv } = options.serverOptions;
|
|
3
|
+
return async (c, next) => {
|
|
4
|
+
const env = getEnv(c);
|
|
5
|
+
const db = getDB(c);
|
|
6
|
+
// use db
|
|
7
|
+
// const storage = new RemoteSQLStorage(db);
|
|
8
|
+
c.set('config', {
|
|
9
|
+
// storage,
|
|
10
|
+
env,
|
|
11
|
+
});
|
|
12
|
+
// // auto setup
|
|
13
|
+
// if (c.req.query('_initDB') == 'true') {
|
|
14
|
+
// await storage.setup();
|
|
15
|
+
// }
|
|
16
|
+
return next();
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/setup.ts"],"names":[],"mappings":"AAoBA,MAAM,UAAU,KAAK,CACpB,OAAgC;IAEhC,MAAM,EAAC,KAAK,EAAE,MAAM,EAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAE9C,OAAO,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QACxB,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAEtB,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACpB,SAAS;QACT,4CAA4C;QAE5C,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE;YACf,WAAW;YACX,GAAG;SACH,CAAC,CAAC;QAEH,gBAAgB;QAChB,0CAA0C;QAC1C,0BAA0B;QAC1B,IAAI;QAEJ,OAAO,IAAI,EAAE,CAAC;IACf,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Context } from 'hono';
|
|
2
|
+
import { Bindings } from 'hono/types';
|
|
3
|
+
import { RemoteSQL } from 'remote-sql';
|
|
4
|
+
export type ServerOptions<Env extends Bindings = Bindings> = {
|
|
5
|
+
getDB: (c: Context<{
|
|
6
|
+
Bindings: Env;
|
|
7
|
+
}>) => RemoteSQL;
|
|
8
|
+
getEnv: (c: Context<{
|
|
9
|
+
Bindings: Env;
|
|
10
|
+
}>) => Env;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,SAAS,EAAC,MAAM,YAAY,CAAC;AAErC,MAAM,MAAM,aAAa,CAAC,GAAG,SAAS,QAAQ,GAAG,QAAQ,IAAI;IAC5D,KAAK,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,GAAG,CAAA;KAAC,CAAC,KAAK,SAAS,CAAC;IAClD,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,GAAG,CAAA;KAAC,CAAC,KAAK,GAAG,CAAC;CAC7C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "faucet-server-app",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "server app",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/esm/index.d.ts",
|
|
13
|
+
"default": "./dist/esm/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"hono": "^4.12.9",
|
|
23
|
+
"named-logs": "^0.4.1",
|
|
24
|
+
"remote-sql": "^0.0.6",
|
|
25
|
+
"viem": "^2.47.6"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"as-soon": "^0.1.5",
|
|
29
|
+
"ldenv": "^0.3.16",
|
|
30
|
+
"prettier": "^3.8.1",
|
|
31
|
+
"typescript": "^5.9.3"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"format:check": "prettier --check .",
|
|
35
|
+
"format": "prettier --write .",
|
|
36
|
+
"build:ts": "tsc --project tsconfig.json",
|
|
37
|
+
"build": "pnpm sql2ts && pnpm build:ts",
|
|
38
|
+
"sql2ts": "node sql2ts.cjs ./src/schema/sql",
|
|
39
|
+
"sql2ts:watch": "pnpm sql2ts && as-soon -w ./src/schema/sql pnpm sql2ts",
|
|
40
|
+
"css2ts": "node css2ts.cjs global",
|
|
41
|
+
"css2ts:watch": "pnpm css2ts && as-soon -w ./src/schema/css pnpm css2ts",
|
|
42
|
+
"dev": "as-soon -w src pnpm build:ts"
|
|
43
|
+
}
|
|
44
|
+
}
|