anyray-connect 0.1.0 → 0.3.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.
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Shareable setup links — `https://app.anyray.ai/setup/<token>`.
3
+ *
4
+ * Admins drop that link in Slack; devs paste it straight into the CLI instead
5
+ * of hunting for the gateway URL. We recognize the `<origin>/setup/<token>`
6
+ * shape and resolve the org's gateway by calling the setup page's info
7
+ * endpoint:
8
+ *
9
+ * GET <origin>/setup-info/<token>
10
+ * → 200 { "org": "<name>", "gateways": [{ "url": "https://…" }], "connected": n }
11
+ *
12
+ * The first gateway's URL becomes the connect target. A plain gateway URL
13
+ * keeps working unchanged — anything that doesn't match the `/setup/<token>`
14
+ * path is not a setup link.
15
+ *
16
+ * SECRECY: the token is a shared credential — never embed it in error
17
+ * messages. Errors carry only the portal origin and the status. Nothing here
18
+ * touches prompt/response content (the endpoint returns org/gateway metadata
19
+ * only).
20
+ */
21
+ const SETUP_INFO_TIMEOUT_MS = 10_000;
22
+ /** Parse `<origin>/setup/<token>` into its parts, or undefined if `raw` is not a setup link. */
23
+ export const parseSetupLink = (raw) => {
24
+ let url;
25
+ try {
26
+ url = new URL(raw.trim());
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ if (url.protocol !== 'http:' && url.protocol !== 'https:')
32
+ return undefined;
33
+ const match = /^\/setup\/([^/]+)\/?$/.exec(url.pathname);
34
+ if (!match)
35
+ return undefined;
36
+ return { origin: url.origin, token: match[1] };
37
+ };
38
+ const optionalString = (value) => typeof value === 'string' && value.trim() ? value.trim() : undefined;
39
+ /** Resolve a setup link to the org's gateway URL via `GET <origin>/setup-info/<token>`. */
40
+ export const resolveSetupLink = async (link, opts = {}) => {
41
+ const timeoutMs = opts.timeoutMs ?? SETUP_INFO_TIMEOUT_MS;
42
+ const url = `${link.origin}/setup-info/${link.token}`;
43
+ const controller = new AbortController();
44
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
45
+ let res;
46
+ try {
47
+ res = await fetch(url, { method: 'GET', signal: controller.signal });
48
+ }
49
+ catch (error) {
50
+ const reason = error instanceof Error && error.name === 'AbortError'
51
+ ? `no response within ${timeoutMs}ms`
52
+ : error instanceof Error
53
+ ? error.message
54
+ : String(error);
55
+ throw new Error(`could not reach the setup page at ${link.origin}: ${reason}`);
56
+ }
57
+ finally {
58
+ clearTimeout(timer);
59
+ }
60
+ if (!res.ok) {
61
+ throw new Error(`setup link lookup failed: ${link.origin} responded ${res.status} — the link may be expired; ask your admin for a fresh one.`);
62
+ }
63
+ let body;
64
+ try {
65
+ body = (await res.json());
66
+ }
67
+ catch {
68
+ throw new Error(`setup link lookup failed: ${link.origin} returned a malformed response`);
69
+ }
70
+ const gateways = Array.isArray(body?.gateways) ? body.gateways : [];
71
+ const gatewayUrl = gateways
72
+ .map((g) => optionalString(g?.url))
73
+ .find((u) => u !== undefined);
74
+ if (!gatewayUrl) {
75
+ throw new Error('this setup link has no gateway configured yet — ask your admin to add a gateway in the Anyray console, then re-run.');
76
+ }
77
+ return {
78
+ gatewayUrl,
79
+ org: optionalString(body.org),
80
+ seatMode: body.seatMode === true,
81
+ };
82
+ };
83
+ //# sourceMappingURL=setupLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setupLink.js","sourceRoot":"","sources":["../../src/util/setupLink.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,qBAAqB,GAAG,MAAM,CAAC;AA4BrC,gGAAgG;AAChG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAyB,EAAE;IACnE,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,KA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;KACjC,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anyray-connect",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Anyray connect — points local coding tools (Claude Code, Cursor, Windsurf, SDKs) at the Anyray gateway by writing their base URL + a placeholder key. The gateway stays the brain; this is just the on-ramp.",
5
5
  "type": "module",
6
6
  "bin": {