crewpay-rest 0.0.0-stage → 0.2.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/README.md +8 -2
- package/dist/client.d.ts +49 -0
- package/dist/client.js +119 -0
- package/package.json +32 -4
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# crewpay-rest
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared CrewPay REST client for framework plugins.
|
|
4
|
+
|
|
5
|
+
- Dry-run returns `dryRunId` + `approvalUrl` (no approve secret)
|
|
6
|
+
- Operator opens `approvalUrl` and wallet-signs
|
|
7
|
+
- `launch` / `wireFees` require approved `dryRunId`
|
|
8
|
+
|
|
9
|
+
Prefer MCP: `npx -y crewpay-mcp@1.2.3`
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal CrewPay REST client for framework plugins.
|
|
3
|
+
* Keys from env only — never accept private keys as function arguments.
|
|
4
|
+
*
|
|
5
|
+
* Spend gate: POST /api/agent/launch/dry-run returns dryRunId + approvalUrl
|
|
6
|
+
* (no approve secret). Operator opens approvalUrl and wallet-signs.
|
|
7
|
+
* Launch/wire require dryRunId after approval. Image content is bound by sha256.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_API_URL = "https://api.crewpay.dev";
|
|
10
|
+
export type CrewPayEnv = {
|
|
11
|
+
apiUrl?: string;
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
launcherKey?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function loadCrewPayEnv(overrides?: CrewPayEnv): Required<Pick<CrewPayEnv, 'apiUrl'>> & CrewPayEnv;
|
|
16
|
+
export declare class CrewPayClient {
|
|
17
|
+
private readonly env;
|
|
18
|
+
constructor(env?: ReturnType<typeof loadCrewPayEnv>);
|
|
19
|
+
private headers;
|
|
20
|
+
fetch(path: string, init?: RequestInit & {
|
|
21
|
+
auth?: boolean;
|
|
22
|
+
launcher?: boolean;
|
|
23
|
+
}): Promise<unknown>;
|
|
24
|
+
discover(): Promise<unknown>;
|
|
25
|
+
claimKey(body?: {
|
|
26
|
+
label?: string;
|
|
27
|
+
agentName?: string;
|
|
28
|
+
model?: string;
|
|
29
|
+
}): Promise<unknown>;
|
|
30
|
+
autohire(body: Record<string, unknown>): Promise<unknown>;
|
|
31
|
+
/** Server dry-run — returns plan + dryRunId + approvalUrl (no approve secret). */
|
|
32
|
+
dryRun(body: Record<string, unknown>): Promise<unknown>;
|
|
33
|
+
launch(body: Record<string, unknown>, opts: {
|
|
34
|
+
dryRunId: string;
|
|
35
|
+
}): Promise<unknown>;
|
|
36
|
+
wireFees(body: {
|
|
37
|
+
mint: string;
|
|
38
|
+
mode?: string;
|
|
39
|
+
crew?: unknown[];
|
|
40
|
+
name?: string;
|
|
41
|
+
ticker?: string;
|
|
42
|
+
}, opts: {
|
|
43
|
+
dryRunId: string;
|
|
44
|
+
}): Promise<unknown>;
|
|
45
|
+
crank(body: {
|
|
46
|
+
mint: string;
|
|
47
|
+
}): Promise<unknown>;
|
|
48
|
+
proof(): Promise<unknown>;
|
|
49
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal CrewPay REST client for framework plugins.
|
|
3
|
+
* Keys from env only — never accept private keys as function arguments.
|
|
4
|
+
*
|
|
5
|
+
* Spend gate: POST /api/agent/launch/dry-run returns dryRunId + approvalUrl
|
|
6
|
+
* (no approve secret). Operator opens approvalUrl and wallet-signs.
|
|
7
|
+
* Launch/wire require dryRunId after approval. Image content is bound by sha256.
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_API_URL = 'https://api.crewpay.dev';
|
|
10
|
+
export function loadCrewPayEnv(overrides = {}) {
|
|
11
|
+
return {
|
|
12
|
+
apiUrl: (overrides.apiUrl || process.env.CREW_API_URL || DEFAULT_API_URL).replace(/\/$/, ''),
|
|
13
|
+
apiKey: overrides.apiKey ||
|
|
14
|
+
process.env.CREWPAY_API_KEY?.trim() ||
|
|
15
|
+
process.env.CREW_AGENT_API_KEY?.trim() ||
|
|
16
|
+
'',
|
|
17
|
+
launcherKey: overrides.launcherKey ||
|
|
18
|
+
process.env.CREW_LAUNCHER_KEY?.trim() ||
|
|
19
|
+
'',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export class CrewPayClient {
|
|
23
|
+
env;
|
|
24
|
+
constructor(env = loadCrewPayEnv()) {
|
|
25
|
+
this.env = env;
|
|
26
|
+
}
|
|
27
|
+
headers(opts) {
|
|
28
|
+
const h = new Headers({ accept: 'application/json', 'content-type': 'application/json' });
|
|
29
|
+
if (this.env.apiKey)
|
|
30
|
+
h.set('x-crew-api-key', this.env.apiKey);
|
|
31
|
+
if (opts?.launcher) {
|
|
32
|
+
if (!this.env.launcherKey) {
|
|
33
|
+
throw new Error('Missing CREW_LAUNCHER_KEY in env — use a dedicated low-SOL burner. Never pass secrets as arguments.');
|
|
34
|
+
}
|
|
35
|
+
h.set('x-launcher-key', this.env.launcherKey);
|
|
36
|
+
}
|
|
37
|
+
return h;
|
|
38
|
+
}
|
|
39
|
+
async fetch(path, init) {
|
|
40
|
+
const headers = this.headers({ launcher: init?.launcher });
|
|
41
|
+
if (init?.auth && !this.env.apiKey) {
|
|
42
|
+
throw new Error('Missing CREWPAY_API_KEY / CREW_AGENT_API_KEY — claim via POST /api/agent/keys/claim');
|
|
43
|
+
}
|
|
44
|
+
const res = await fetch(`${this.env.apiUrl}${path}`, { ...init, headers });
|
|
45
|
+
const text = await res.text();
|
|
46
|
+
let json = null;
|
|
47
|
+
try {
|
|
48
|
+
json = text ? JSON.parse(text) : null;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
json = { raw: text.slice(0, 500) };
|
|
52
|
+
}
|
|
53
|
+
if (!res.ok) {
|
|
54
|
+
const err = typeof json === 'object' && json && 'error' in json
|
|
55
|
+
? String(json.error)
|
|
56
|
+
: text.slice(0, 300);
|
|
57
|
+
throw new Error(`CREW API ${res.status}: ${err}`);
|
|
58
|
+
}
|
|
59
|
+
return json;
|
|
60
|
+
}
|
|
61
|
+
discover() {
|
|
62
|
+
return this.fetch('/api/agent');
|
|
63
|
+
}
|
|
64
|
+
claimKey(body = {}) {
|
|
65
|
+
return this.fetch('/api/agent/keys/claim', {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
body: JSON.stringify({ label: 'agent', ...body }),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
autohire(body) {
|
|
71
|
+
return this.fetch('/api/agent/autohire', {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
auth: true,
|
|
74
|
+
body: JSON.stringify(body),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** Server dry-run — returns plan + dryRunId + approvalUrl (no approve secret). */
|
|
78
|
+
dryRun(body) {
|
|
79
|
+
return this.fetch('/api/agent/launch/dry-run', {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
auth: true,
|
|
82
|
+
body: JSON.stringify(body),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
launch(body, opts) {
|
|
86
|
+
const dryRunId = String(opts.dryRunId || '').trim();
|
|
87
|
+
if (!dryRunId) {
|
|
88
|
+
throw new Error('Launch blocked: dryRunId required — dry-run, operator wallet-approves on approvalUrl, then launch');
|
|
89
|
+
}
|
|
90
|
+
return this.fetch('/api/agent/launch', {
|
|
91
|
+
method: 'POST',
|
|
92
|
+
auth: true,
|
|
93
|
+
launcher: true,
|
|
94
|
+
body: JSON.stringify({ ...body, dryRunId }),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
wireFees(body, opts) {
|
|
98
|
+
const dryRunId = String(opts.dryRunId || '').trim();
|
|
99
|
+
if (!dryRunId) {
|
|
100
|
+
throw new Error('Wire-fees blocked: dryRunId required — dry-run with intent=wire-fees, wallet-approve, then wire');
|
|
101
|
+
}
|
|
102
|
+
return this.fetch('/api/agent/wire-fees', {
|
|
103
|
+
method: 'POST',
|
|
104
|
+
auth: true,
|
|
105
|
+
launcher: true,
|
|
106
|
+
body: JSON.stringify({ ...body, dryRunId }),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
crank(body) {
|
|
110
|
+
return this.fetch('/api/agent/crank', {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
auth: true,
|
|
113
|
+
body: JSON.stringify(body),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
proof() {
|
|
117
|
+
return this.fetch('/api/proof');
|
|
118
|
+
}
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crewpay-rest",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Shared CrewPay REST client — dry-run + wallet-approved dryRunId for launch/wire. Env keys only.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/client.js",
|
|
7
|
+
"types": "./dist/client.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/client.d.ts",
|
|
11
|
+
"import": "./dist/client.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist", "README.md"],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -p tsconfig.json",
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"prepublishOnly": "npm run build"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/fxams/crew.git",
|
|
24
|
+
"directory": "packages/crewpay-rest"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://crewpay.dev/agents",
|
|
27
|
+
"publishConfig": { "access": "public" },
|
|
28
|
+
"engines": { "node": ">=20" },
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^22.10.0",
|
|
31
|
+
"typescript": "^5.7.0",
|
|
32
|
+
"vitest": "^5.0.3"
|
|
33
|
+
}
|
|
34
|
+
}
|