@securespoon/sdk 0.1.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # @securespoon/sdk
2
+
3
+ Typed client and CLI for the [SecureSpoon](https://securespoon.com) governed
4
+ control plane. Zero dependencies; Node 18+ (uses the global `fetch`).
5
+
6
+ SecureSpoon's server-side AND-gate does all enforcement — an SDK call can do
7
+ exactly what its API key's access scopes allow (`read` / `run` / `manage`),
8
+ never more, and never anything admin-only. The client adds no privilege; it
9
+ only speaks the protocol.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @securespoon/sdk
15
+ ```
16
+
17
+ ## Getting a key
18
+
19
+ Console → **Settings → API keys** → create. The secret (`ss_live_…`) is shown
20
+ **once**; the server stores only a hash. Pick the narrowest scopes that work:
21
+
22
+ | scope | grants |
23
+ |----------|--------|
24
+ | `read` | read-only across the workspace + verifying receipts |
25
+ | `run` | asking agents; running workflows, applications, MCP tools, triggers |
26
+ | `manage` | everything an operator can do (never admin) |
27
+
28
+ ## Client
29
+
30
+ ```ts
31
+ import { SecureSpoon } from "@securespoon/sdk";
32
+
33
+ const client = new SecureSpoon({
34
+ apiKey: process.env.SECURESPOON_API_KEY,
35
+ baseUrl: "https://console.example.com",
36
+ });
37
+
38
+ const turn = await client.ask({ agent: "support-copilot", question: "Status of order 10432?" });
39
+ console.log(turn.answer, turn.risk?.label);
40
+
41
+ const receipts = await client.receipts.list();
42
+ const verdict = await client.receipts.verify(receipts[0]); // server-side re-sign + compare
43
+ ```
44
+
45
+ Errors throw `SecureSpoonError` with `.status` (401 bad/expired key, 403 out
46
+ of scope, 400 invalid input) and `.messages` (the server's own words).
47
+
48
+ ## CLI — `securespoon` (ships in this package)
49
+
50
+ ```
51
+ securespoon login # paste console URL + key; verified, then saved 0600
52
+ securespoon ask "…" --agent support-copilot
53
+ securespoon servers # includes each server's red-team verdict
54
+ securespoon servers redteam <id> # exit 0 = passed, 1 = findings
55
+ securespoon receipts verify <id> # exit 0 = signature valid
56
+ securespoon keys
57
+ ```
58
+
59
+ Config lives in `~/.securespoon.json` (written `0600`). Environment overrides
60
+ for CI: `SECURESPOON_API_KEY`, `SECURESPOON_BASE_URL`, `SECURESPOON_CONFIG`.
61
+
62
+ ## License
63
+
64
+ Apache-2.0
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * securespoon — CLI over @securespoon/sdk.
4
+ *
5
+ * Auth: `securespoon login` stores the console URL + API key in
6
+ * ~/.securespoon.json (0600). SECURESPOON_API_KEY / SECURESPOON_BASE_URL
7
+ * override the stored config; SECURESPOON_CONFIG relocates the file (CI).
8
+ * The key is minted in the console (Settings → API keys) and shown once —
9
+ * the CLI never sees or stores anything the server could re-reveal.
10
+ */
11
+ import fs from "node:fs";
12
+ import os from "node:os";
13
+ import path from "node:path";
14
+ import readline from "node:readline";
15
+ import { SecureSpoon, SecureSpoonError } from "../src/index.mjs";
16
+
17
+ const CONFIG_PATH = process.env.SECURESPOON_CONFIG ?? path.join(os.homedir(), ".securespoon.json");
18
+
19
+ const HELP = `securespoon — the SecureSpoon control-plane CLI
20
+
21
+ USAGE
22
+ securespoon login [--url <console-url>] [--key <api-key>]
23
+ securespoon whoami
24
+ securespoon ask "<question>" [--agent <agent-id>]
25
+ securespoon servers [--json]
26
+ securespoon servers redteam <server-id>
27
+ securespoon receipts [--json]
28
+ securespoon receipts verify <receipt-id>
29
+ securespoon keys
30
+
31
+ AUTH
32
+ Keys are minted in the console (Settings → API keys). "login" verifies the
33
+ key against the console before saving. Env overrides: SECURESPOON_API_KEY,
34
+ SECURESPOON_BASE_URL, SECURESPOON_CONFIG.`;
35
+
36
+ function readConfig() {
37
+ try { return JSON.parse(fs.readFileSync(CONFIG_PATH, "utf8")); } catch { return {}; }
38
+ }
39
+ function writeConfig(cfg) {
40
+ fs.writeFileSync(CONFIG_PATH, JSON.stringify(cfg, null, 2) + "\n", { mode: 0o600 });
41
+ }
42
+ function flag(args, name) {
43
+ const i = args.indexOf(name);
44
+ if (i === -1) return undefined;
45
+ const v = args[i + 1];
46
+ args.splice(i, 2);
47
+ return v;
48
+ }
49
+ function prompt(q, { hidden = false } = {}) {
50
+ return new Promise((resolve) => {
51
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
52
+ if (hidden && process.stdin.isTTY) {
53
+ // mask key entry: echo nothing after the prompt
54
+ process.stdout.write(q);
55
+ const chars = [];
56
+ process.stdin.setRawMode(true);
57
+ process.stdin.on("data", function onData(b) {
58
+ const s = b.toString("utf8");
59
+ if (s === "\r" || s === "\n" || s === "\u0004") {
60
+ process.stdin.setRawMode(false);
61
+ process.stdin.removeListener("data", onData);
62
+ rl.close();
63
+ process.stdout.write("\n");
64
+ resolve(chars.join(""));
65
+ } else if (s === "\u0003") {
66
+ process.exit(130);
67
+ } else if (s === "\u007f") {
68
+ chars.pop();
69
+ } else {
70
+ chars.push(s);
71
+ }
72
+ });
73
+ } else {
74
+ rl.question(q, (a) => { rl.close(); resolve(a.trim()); });
75
+ }
76
+ });
77
+ }
78
+ function client() {
79
+ const cfg = readConfig();
80
+ const apiKey = process.env.SECURESPOON_API_KEY ?? cfg.apiKey;
81
+ const baseUrl = process.env.SECURESPOON_BASE_URL ?? cfg.baseUrl;
82
+ if (!apiKey || !baseUrl) {
83
+ console.error("Not logged in. Run: securespoon login");
84
+ process.exit(2);
85
+ }
86
+ return new SecureSpoon({ apiKey, baseUrl });
87
+ }
88
+ const mask = (k) => `${k.slice(0, 14)}••••••••`;
89
+
90
+ async function main() {
91
+ const args = process.argv.slice(2);
92
+ const cmd = args.shift();
93
+
94
+ if (!cmd || cmd === "help" || cmd === "--help" || cmd === "-h") {
95
+ console.log(HELP);
96
+ return;
97
+ }
98
+
99
+ if (cmd === "login") {
100
+ const url = flag(args, "--url") ?? (await prompt("Console URL (https://…): "));
101
+ const key = flag(args, "--key") ?? (await prompt("API key (orx_live_…): ", { hidden: true }));
102
+ const c = new SecureSpoon({ apiKey: key, baseUrl: url });
103
+ // Verify before saving: a read call. 403 means valid key without read
104
+ // scope (a run-only key) — still worth saving; 401 means a bad key.
105
+ try {
106
+ await c.workspaces.list();
107
+ } catch (e) {
108
+ if (e instanceof SecureSpoonError && e.status === 401) {
109
+ console.error("That key was refused by the console (401) — not saved.");
110
+ process.exit(1);
111
+ }
112
+ if (!(e instanceof SecureSpoonError && e.status === 403)) throw e;
113
+ }
114
+ writeConfig({ baseUrl: c.baseUrl, apiKey: key });
115
+ console.log(`Logged in to ${c.baseUrl} as ${mask(key)} (saved to ${CONFIG_PATH}).`);
116
+ return;
117
+ }
118
+
119
+ if (cmd === "whoami") {
120
+ const cfg = readConfig();
121
+ const apiKey = process.env.SECURESPOON_API_KEY ?? cfg.apiKey;
122
+ const baseUrl = process.env.SECURESPOON_BASE_URL ?? cfg.baseUrl;
123
+ if (!apiKey || !baseUrl) { console.log("Not logged in."); process.exit(2); }
124
+ console.log(`${baseUrl} ${mask(apiKey)}`);
125
+ return;
126
+ }
127
+
128
+ if (cmd === "ask") {
129
+ const agent = flag(args, "--agent");
130
+ const json = args.includes("--json");
131
+ const question = args.filter((a) => a !== "--json").join(" ").trim();
132
+ if (!question) { console.error('Usage: securespoon ask "<question>" [--agent <id>]'); process.exit(2); }
133
+ const turn = await client().ask({ agent, question });
134
+ if (json) { console.log(JSON.stringify(turn, null, 2)); return; }
135
+ console.log(turn.answer);
136
+ if (turn.risk) console.error(`\n[risk: ${turn.risk.label}] [agent: ${turn.agentId} v${turn.agentVersion}]`);
137
+ return;
138
+ }
139
+
140
+ if (cmd === "servers") {
141
+ const sub = args[0];
142
+ if (sub === "redteam") {
143
+ const id = args[1];
144
+ if (!id) { console.error("Usage: securespoon servers redteam <server-id>"); process.exit(2); }
145
+ const out = await client().mcpServers.redteam(id);
146
+ console.log(JSON.stringify(out, null, 2));
147
+ process.exit(out.result?.status === "passed" ? 0 : 1);
148
+ }
149
+ const servers = await client().mcpServers.list();
150
+ if (args.includes("--json")) { console.log(JSON.stringify(servers, null, 2)); return; }
151
+ for (const s of servers) {
152
+ const rt = s.redTeam ? `red-team ${s.redTeam.status} (${s.redTeam.checksRun} checks)` : "red-team not run";
153
+ console.log(`${s.id} ${s.status.padEnd(8)} ${rt.padEnd(32)} ${s.name}`);
154
+ }
155
+ return;
156
+ }
157
+
158
+ if (cmd === "receipts") {
159
+ const sub = args[0];
160
+ const c = client();
161
+ if (sub === "verify") {
162
+ const id = args[1];
163
+ if (!id) { console.error("Usage: securespoon receipts verify <receipt-id>"); process.exit(2); }
164
+ const receipt = await c.receipts.get(id);
165
+ if (!receipt) { console.error(`No receipt ${id}.`); process.exit(1); }
166
+ const v = await c.receipts.verify(receipt);
167
+ console.log(JSON.stringify(v, null, 2));
168
+ process.exit(v.verified ? 0 : 1);
169
+ }
170
+ const receipts = await c.receipts.list();
171
+ if (args.includes("--json")) { console.log(JSON.stringify(receipts, null, 2)); return; }
172
+ for (const r of receipts) console.log(`${r.id} ${r.issuedAtIso} ${r.actor} ${(r.run?.question ?? "").slice(0, 60)}`);
173
+ return;
174
+ }
175
+
176
+ if (cmd === "keys") {
177
+ const keys = await client().apiKeys.list();
178
+ for (const k of keys) console.log(`${k.id} ${k.prefix} scopes=${(k.accessScopes ?? []).join(",")} expires=${k.expiresAtIso ?? "never"}`);
179
+ return;
180
+ }
181
+
182
+ console.error(`Unknown command: ${cmd}\n`);
183
+ console.log(HELP);
184
+ process.exit(2);
185
+ }
186
+
187
+ main().catch((e) => {
188
+ if (e instanceof SecureSpoonError) {
189
+ console.error(`Error ${e.status}: ${e.message}`);
190
+ process.exit(1);
191
+ }
192
+ console.error(e.message ?? String(e));
193
+ process.exit(1);
194
+ });
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@securespoon/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Typed client and CLI for the SecureSpoon governed control plane.",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://securespoon.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/gittergov/multitenant.git",
10
+ "directory": "sdk/typescript"
11
+ },
12
+ "keywords": [
13
+ "securespoon",
14
+ "mcp",
15
+ "agents",
16
+ "governance",
17
+ "api-client",
18
+ "cli"
19
+ ],
20
+ "type": "module",
21
+ "main": "src/index.mjs",
22
+ "types": "src/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./src/index.d.ts",
26
+ "default": "./src/index.mjs"
27
+ }
28
+ },
29
+ "bin": {
30
+ "securespoon": "bin/securespoon.mjs"
31
+ },
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "files": [
36
+ "src",
37
+ "bin",
38
+ "README.md",
39
+ "LICENSE"
40
+ ]
41
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Type declarations for @securespoon/sdk. The wire shapes are the console's
3
+ * REST responses; fields beyond the ones named here ride through untyped.
4
+ */
5
+
6
+ export interface SecureSpoonOptions {
7
+ /** A minted API key (`ss_live_…`). Falls back to SECURESPOON_API_KEY. */
8
+ apiKey?: string;
9
+ /** Console origin, e.g. "https://console.example.com". Falls back to SECURESPOON_BASE_URL. */
10
+ baseUrl?: string;
11
+ /** Override fetch (tests). */
12
+ fetch?: typeof fetch;
13
+ }
14
+
15
+ /** One governed run through the five-gate pipeline. */
16
+ export interface AgentTurn {
17
+ question: string;
18
+ answer: string;
19
+ agentId: string;
20
+ agentVersion: number;
21
+ risk?: { label: string; reasons: string[] };
22
+ guardrail: Record<string, unknown>;
23
+ classification: Record<string, unknown>;
24
+ residency: Record<string, unknown>;
25
+ resilience: Record<string, unknown>;
26
+ quota: Record<string, unknown>;
27
+ cost: Record<string, unknown>;
28
+ [key: string]: unknown;
29
+ }
30
+
31
+ /** A signed, shareable run receipt. */
32
+ export interface Receipt {
33
+ id: string;
34
+ workspaceId: string;
35
+ actor: string;
36
+ issuedAtIso: string;
37
+ run: AgentTurn;
38
+ pricesArePlaceholder: boolean;
39
+ signature: string;
40
+ signatureAlg: string;
41
+ [key: string]: unknown;
42
+ }
43
+
44
+ export interface ReceiptVerification {
45
+ receiptId: string;
46
+ verified: boolean;
47
+ reason: string;
48
+ }
49
+
50
+ export interface McpServer {
51
+ id: string;
52
+ name: string;
53
+ status: string;
54
+ endpoint?: string;
55
+ redTeam?: {
56
+ status: "passed" | "failed";
57
+ checksRun: number;
58
+ findings: { check: string; tool: string; detail: string }[];
59
+ atIso: string;
60
+ corpusVersion: string;
61
+ };
62
+ tools?: { id: string; name: string; description?: string }[];
63
+ [key: string]: unknown;
64
+ }
65
+
66
+ export declare class SecureSpoonError extends Error {
67
+ status: number;
68
+ messages: string[];
69
+ constructor(status: number, messages: string[]);
70
+ }
71
+
72
+ export declare class SecureSpoon {
73
+ constructor(options?: SecureSpoonOptions);
74
+ apiKey: string;
75
+ baseUrl: string;
76
+
77
+ /** Ask an agent through the governed path. */
78
+ ask(input: { agent?: string; question: string }): Promise<AgentTurn>;
79
+
80
+ receipts: {
81
+ list(): Promise<Receipt[]>;
82
+ get(id: string): Promise<Receipt | null>;
83
+ create(input: { workspaceId: string; run: AgentTurn } & Record<string, unknown>): Promise<Receipt>;
84
+ verify(receipt: Receipt): Promise<ReceiptVerification>;
85
+ };
86
+
87
+ mcpServers: {
88
+ list(): Promise<McpServer[]>;
89
+ create(input: Record<string, unknown>): Promise<McpServer>;
90
+ redteam(id: string): Promise<{ result: NonNullable<McpServer["redTeam"]>; status: string; regression: boolean }>;
91
+ call(id: string, input: { toolId: string; input: string }): Promise<unknown>;
92
+ };
93
+
94
+ workspaces: {
95
+ list(): Promise<Record<string, unknown>[]>;
96
+ create(input: Record<string, unknown>): Promise<Record<string, unknown>>;
97
+ };
98
+
99
+ agents: { list(): Promise<Record<string, unknown>[]> };
100
+ apiKeys: { list(): Promise<Record<string, unknown>[]> };
101
+ }
102
+
103
+ export default SecureSpoon;
package/src/index.mjs ADDED
@@ -0,0 +1,105 @@
1
+ /**
2
+ * @securespoon/sdk — a thin, typed client over the SecureSpoon console's REST
3
+ * API. Zero dependencies; Node 18+ (global fetch).
4
+ *
5
+ * Every call authenticates with a minted API key (Settings → API keys). The
6
+ * key's ACCESS SCOPES bound what the client may do server-side — read / run /
7
+ * manage — and the server's AND-gate enforces them on every route; this
8
+ * client adds no privilege, it only speaks the protocol.
9
+ *
10
+ * import { SecureSpoon } from "@securespoon/sdk";
11
+ * const client = new SecureSpoon({
12
+ * apiKey: process.env.SECURESPOON_API_KEY,
13
+ * baseUrl: "https://console.example.com",
14
+ * });
15
+ * const turn = await client.ask({ agent: "support-copilot", question: "…" });
16
+ * console.log(turn.answer);
17
+ */
18
+
19
+ export class SecureSpoonError extends Error {
20
+ constructor(status, messages) {
21
+ super(messages.length ? messages.join("; ") : `HTTP ${status}`);
22
+ this.name = "SecureSpoonError";
23
+ /** HTTP status of the failed call (401 bad/expired key, 403 out of scope, 400 invalid input). */
24
+ this.status = status;
25
+ /** Server-supplied error messages, verbatim. */
26
+ this.messages = messages;
27
+ }
28
+ }
29
+
30
+ export class SecureSpoon {
31
+ constructor({ apiKey, baseUrl, fetch: fetchImpl } = {}) {
32
+ this.apiKey = apiKey ?? process.env.SECURESPOON_API_KEY;
33
+ this.baseUrl = (baseUrl ?? process.env.SECURESPOON_BASE_URL ?? "").replace(/\/+$/, "");
34
+ if (!this.apiKey) throw new Error("SecureSpoon: apiKey is required (or set SECURESPOON_API_KEY).");
35
+ if (!this.baseUrl) throw new Error("SecureSpoon: baseUrl is required (or set SECURESPOON_BASE_URL).");
36
+ this._fetch = fetchImpl ?? globalThis.fetch;
37
+
38
+ /** Signed run receipts: list, fetch one, mint from a run, verify an artifact. */
39
+ this.receipts = {
40
+ list: () => this._req("GET", "/api/receipts"),
41
+ get: (id) => this._req("GET", `/api/receipts/${encodeURIComponent(id)}`),
42
+ create: (input) => this._req("POST", "/api/receipts", input),
43
+ /** Server-side re-sign + compare of the FULL artifact you hold. */
44
+ verify: (receipt) => this._req("POST", `/api/receipts/${encodeURIComponent(receipt.id)}/verify`, receipt),
45
+ };
46
+
47
+ /** Registered MCP servers (every registration is red-teamed before trust). */
48
+ this.mcpServers = {
49
+ list: () => this._req("GET", "/api/mcp-servers"),
50
+ create: (input) => this._req("POST", "/api/mcp-servers", input),
51
+ /** Re-run the red-team gate; a regression pauses the server + alerts. */
52
+ redteam: (id) => this._req("POST", `/api/mcp-servers/${encodeURIComponent(id)}/redteam`, {}),
53
+ call: (id, input) => this._req("POST", `/api/mcp-servers/${encodeURIComponent(id)}/call`, input),
54
+ };
55
+
56
+ this.workspaces = {
57
+ list: () => this._req("GET", "/api/workspaces"),
58
+ create: (input) => this._req("POST", "/api/workspaces", input),
59
+ };
60
+
61
+ this.agents = {
62
+ list: () => this._req("GET", "/api/agents"),
63
+ };
64
+
65
+ /** Key metadata — masked prefixes only; the server never returns a secret. */
66
+ this.apiKeys = {
67
+ list: () => this._req("GET", "/api/api-keys"),
68
+ };
69
+ }
70
+
71
+ /**
72
+ * Ask an agent through the governed path — the same five-gate pipeline the
73
+ * console runs (guardrails, classification, residency, resilience, quota).
74
+ * Returns the full turn; `answer` is the reply, `risk` the server's scoring.
75
+ */
76
+ async ask({ agent, question }) {
77
+ const body = { question };
78
+ if (agent && agent !== "current") body.target = { type: "agent", id: agent };
79
+ return this._req("POST", "/api/ask", body);
80
+ }
81
+
82
+ async _req(method, path, body) {
83
+ const headers = { authorization: `Bearer ${this.apiKey}` };
84
+ if (body !== undefined) headers["content-type"] = "application/json";
85
+ const res = await this._fetch(`${this.baseUrl}${path}`, {
86
+ method,
87
+ headers,
88
+ body: body !== undefined ? JSON.stringify(body) : undefined,
89
+ });
90
+ const text = await res.text();
91
+ let json = null;
92
+ try { json = text ? JSON.parse(text) : null; } catch { /* non-JSON error body */ }
93
+ if (!res.ok) {
94
+ const messages = Array.isArray(json?.issues) && json.issues.length
95
+ ? json.issues
96
+ : json?.error
97
+ ? [json.error]
98
+ : [];
99
+ throw new SecureSpoonError(res.status, messages);
100
+ }
101
+ return json;
102
+ }
103
+ }
104
+
105
+ export default SecureSpoon;