@mattstack/rt-client 0.1.1 → 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/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { RtResponse, RtClientOptions } from "./transport.ts";
2
- import type { DemandDecl, ProjectMRsData, DiscussionsData, MrByBranchData } from "./commands.ts";
2
+ import type { DemandDecl, ProjectMRsData, DiscussionsData, MrByBranchData, ForgeSlug, ForgeTokenData } from "./commands.ts";
3
3
  /**
4
4
  * One repo's project open-MR store. A cold repo forces a full paginated sync
5
5
  * on the daemon side when maxAgeMs demands it, which can run tens of seconds
@@ -13,3 +13,11 @@ import type { DemandDecl, ProjectMRsData, DiscussionsData, MrByBranchData } from
13
13
  export declare function readProjectMRs(repoName: string, maxAgeMs?: number, opts?: RtClientOptions, demand?: DemandDecl): Promise<RtResponse<ProjectMRsData>>;
14
14
  export declare function readDiscussions(repoName: string, iid: number, opts?: RtClientOptions): Promise<RtResponse<DiscussionsData>>;
15
15
  export declare function readMrsByBranch(repoName: string, branches: string[], opts?: RtClientOptions): Promise<RtResponse<MrByBranchData>>;
16
+ /**
17
+ * The forge token for one tracked repo (MAT-33). Grant-gated on the daemon
18
+ * side: an untracked repo comes back `ok: false` with the `rt daemon track`
19
+ * command to run, which is the fail-closed shape callers should surface
20
+ * verbatim. Callers keep env-var precedence on their own side; this is the
21
+ * fallback that replaces reading ~/.rt/secrets.json directly.
22
+ */
23
+ export declare function resolveForgeToken(repoName: string, forge: ForgeSlug, opts?: RtClientOptions): Promise<RtResponse<ForgeTokenData>>;
@@ -40,6 +40,11 @@ export interface MrByBranchData {
40
40
  byBranch: Record<string, MrByBranchEntry | null>;
41
41
  syncedAt: number;
42
42
  }
43
+ /** Forges the daemon can hold a token for. */
44
+ export type ForgeSlug = "gitlab" | "github";
45
+ export interface ForgeTokenData {
46
+ token: string;
47
+ }
43
48
  export interface Commands {
44
49
  "project-mrs:read": {
45
50
  payload: {
@@ -63,6 +68,20 @@ export interface Commands {
63
68
  };
64
69
  data: MrByBranchData;
65
70
  };
71
+ /**
72
+ * The forge token for one tracked repo (MAT-33). Repo-scoped on purpose:
73
+ * rt gates access per repo through repo-tracking.json, and this verb is
74
+ * what lets consumers stop reading ~/.rt/secrets.json directly, which
75
+ * walked around that grant model entirely. An untracked repo is refused;
76
+ * the caller's env vars keep precedence on the caller's side.
77
+ */
78
+ "secrets:forge-token": {
79
+ payload: {
80
+ repoName: string;
81
+ forge: ForgeSlug;
82
+ };
83
+ data: ForgeTokenData;
84
+ };
66
85
  }
67
86
  export type CommandName = keyof Commands;
68
87
  export declare const COMMAND_NAMES: readonly CommandName[];
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { rtCommand, DEFAULT_SOCK } from "./transport.ts";
2
2
  export type { RtResponse, RtClientOptions } from "./transport.ts";
3
- export { readProjectMRs, readDiscussions, readMrsByBranch } from "./client.ts";
3
+ export { readProjectMRs, readDiscussions, readMrsByBranch, resolveForgeToken } from "./client.ts";
4
4
  export { COMMAND_NAMES } from "./commands.ts";
5
- export type { Discussion, DemandDecl, ProjectMRsScope, ProjectMRsData, DiscussionsData, MrByBranchEntry, MrByBranchData, Commands, CommandName, } from "./commands.ts";
5
+ export type { Discussion, DemandDecl, ProjectMRsScope, ProjectMRsData, DiscussionsData, MrByBranchEntry, MrByBranchData, Commands, CommandName, ForgeSlug, ForgeTokenData, } from "./commands.ts";
6
6
  export { subscribe, DEFAULT_WS_URL } from "./relay.ts";
7
7
  export type { RelayEventType } from "./relay.ts";
8
8
  export { repoNameForPath } from "./repos.ts";
package/dist/index.js CHANGED
@@ -33,8 +33,16 @@ function readDiscussions(repoName, iid, opts = {}) {
33
33
  function readMrsByBranch(repoName, branches, opts = {}) {
34
34
  return rtCommand("mr:by-branch", { repoName, branches }, { sockPath: opts.sockPath, timeoutMs: 60000 });
35
35
  }
36
+ function resolveForgeToken(repoName, forge, opts = {}) {
37
+ return rtCommand("secrets:forge-token", { repoName, forge }, { sockPath: opts.sockPath, timeoutMs: 1e4 });
38
+ }
36
39
  // src/commands.ts
37
- var COMMAND_NAMES = ["project-mrs:read", "discussions:read", "mr:by-branch"];
40
+ var COMMAND_NAMES = [
41
+ "project-mrs:read",
42
+ "discussions:read",
43
+ "mr:by-branch",
44
+ "secrets:forge-token"
45
+ ];
38
46
  // src/relay.ts
39
47
  var DEFAULT_WS_URL = "ws://127.0.0.1:9401/ws";
40
48
  function subscribe(onEvent, opts = {}) {
@@ -104,6 +112,7 @@ function repoNameForPath(repoPath, reposJsonPath) {
104
112
  export {
105
113
  subscribe,
106
114
  rtCommand,
115
+ resolveForgeToken,
107
116
  repoNameForPath,
108
117
  readProjectMRs,
109
118
  readMrsByBranch,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mattstack/rt-client",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
package/src/client.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { rtCommand } from "./transport.ts";
7
7
  import type { RtResponse, RtClientOptions } from "./transport.ts";
8
- import type { DemandDecl, ProjectMRsData, DiscussionsData, MrByBranchData } from "./commands.ts";
8
+ import type { DemandDecl, ProjectMRsData, DiscussionsData, MrByBranchData, ForgeSlug, ForgeTokenData } from "./commands.ts";
9
9
 
10
10
  /**
11
11
  * One repo's project open-MR store. A cold repo forces a full paginated sync
@@ -52,3 +52,22 @@ export function readMrsByBranch(
52
52
  { sockPath: opts.sockPath, timeoutMs: 60_000 },
53
53
  );
54
54
  }
55
+
56
+ /**
57
+ * The forge token for one tracked repo (MAT-33). Grant-gated on the daemon
58
+ * side: an untracked repo comes back `ok: false` with the `rt daemon track`
59
+ * command to run, which is the fail-closed shape callers should surface
60
+ * verbatim. Callers keep env-var precedence on their own side; this is the
61
+ * fallback that replaces reading ~/.rt/secrets.json directly.
62
+ */
63
+ export function resolveForgeToken(
64
+ repoName: string,
65
+ forge: ForgeSlug,
66
+ opts: RtClientOptions = {},
67
+ ): Promise<RtResponse<ForgeTokenData>> {
68
+ return rtCommand<ForgeTokenData>(
69
+ "secrets:forge-token",
70
+ { repoName, forge },
71
+ { sockPath: opts.sockPath, timeoutMs: 10_000 },
72
+ );
73
+ }
package/src/commands.ts CHANGED
@@ -45,12 +45,32 @@ export interface MrByBranchData {
45
45
  syncedAt: number;
46
46
  }
47
47
 
48
+ /** Forges the daemon can hold a token for. */
49
+ export type ForgeSlug = "gitlab" | "github";
50
+
51
+ export interface ForgeTokenData {
52
+ token: string;
53
+ }
54
+
48
55
  export interface Commands {
49
56
  "project-mrs:read": { payload: { repoName: string; maxAgeMs?: number; demand?: DemandDecl }; data: ProjectMRsData };
50
57
  "discussions:read": { payload: { repoName: string; iid: number }; data: DiscussionsData };
51
58
  "mr:by-branch": { payload: { repoName: string; branches: string[] }; data: MrByBranchData };
59
+ /**
60
+ * The forge token for one tracked repo (MAT-33). Repo-scoped on purpose:
61
+ * rt gates access per repo through repo-tracking.json, and this verb is
62
+ * what lets consumers stop reading ~/.rt/secrets.json directly, which
63
+ * walked around that grant model entirely. An untracked repo is refused;
64
+ * the caller's env vars keep precedence on the caller's side.
65
+ */
66
+ "secrets:forge-token": { payload: { repoName: string; forge: ForgeSlug }; data: ForgeTokenData };
52
67
  }
53
68
 
54
69
  export type CommandName = keyof Commands;
55
70
 
56
- export const COMMAND_NAMES: readonly CommandName[] = ["project-mrs:read", "discussions:read", "mr:by-branch"];
71
+ export const COMMAND_NAMES: readonly CommandName[] = [
72
+ "project-mrs:read",
73
+ "discussions:read",
74
+ "mr:by-branch",
75
+ "secrets:forge-token",
76
+ ];
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { rtCommand, DEFAULT_SOCK } from "./transport.ts";
2
2
  export type { RtResponse, RtClientOptions } from "./transport.ts";
3
3
 
4
- export { readProjectMRs, readDiscussions, readMrsByBranch } from "./client.ts";
4
+ export { readProjectMRs, readDiscussions, readMrsByBranch, resolveForgeToken } from "./client.ts";
5
5
 
6
6
  export { COMMAND_NAMES } from "./commands.ts";
7
7
  export type {
@@ -14,6 +14,8 @@ export type {
14
14
  MrByBranchData,
15
15
  Commands,
16
16
  CommandName,
17
+ ForgeSlug,
18
+ ForgeTokenData,
17
19
  } from "./commands.ts";
18
20
 
19
21
  export { subscribe, DEFAULT_WS_URL } from "./relay.ts";