@hanzo/build 0.2.125 → 0.2.126

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/lib/api/work.d.ts CHANGED
@@ -7,6 +7,13 @@
7
7
  * GET /v1/task/board every issue and pull request: the forge's, and the task index's
8
8
  * GET /v1/task/projects the boards
9
9
  * GET /v1/task/projects/{key}/issues one board's
10
+ * POST /v1/git/workspace set the org's code workspace up for the caller
11
+ *
12
+ * In a workspace the platform made for the org, the board is read as the
13
+ * person's own forge account, seated there by POST /v1/git/workspace (cloud
14
+ * apps/git workspace.go). Nothing else seats them, so a board refused for want of
15
+ * a seat — or of the org's namespace — opens the workspace and is read again
16
+ * (`seated`).
10
17
  *
11
18
  * A project is a repository, so the list is those sources merged (merge.ts) and
12
19
  * not a second copy of them. An issue row from the board is read for what it
@@ -32,6 +39,8 @@ export interface Board {
32
39
  export declare function board(raw: unknown): Board | null;
33
40
  /** One board row as an issue: what it is, where it lives, and which repository it says it is for. */
34
41
  export declare function work(raw: unknown): Issue | null;
42
+ /** Set the org's code workspace up for the caller: its namespace, and their forge account and seat. Idempotent. */
43
+ export declare function open(t: Target): Promise<unknown>;
35
44
  export declare function boards(t: Target, signal?: AbortSignal): Promise<Board[]>;
36
45
  /** Every issue and pull request the org has, from the forge and the task index, each once. */
37
46
  export declare function everything(t: Target, signal?: AbortSignal): Promise<Issue[]>;
package/lib/api/work.js CHANGED
@@ -7,6 +7,13 @@
7
7
  * GET /v1/task/board every issue and pull request: the forge's, and the task index's
8
8
  * GET /v1/task/projects the boards
9
9
  * GET /v1/task/projects/{key}/issues one board's
10
+ * POST /v1/git/workspace set the org's code workspace up for the caller
11
+ *
12
+ * In a workspace the platform made for the org, the board is read as the
13
+ * person's own forge account, seated there by POST /v1/git/workspace (cloud
14
+ * apps/git workspace.go). Nothing else seats them, so a board refused for want of
15
+ * a seat — or of the org's namespace — opens the workspace and is read again
16
+ * (`seated`).
10
17
  *
11
18
  * A project is a repository, so the list is those sources merged (merge.ts) and
12
19
  * not a second copy of them. An issue row from the board is read for what it
@@ -19,7 +26,7 @@
19
26
  * Creating, renaming and deleting a board are forge operations. This surface
20
27
  * reads the work and opens a run against it.
21
28
  */
22
- import { call } from './call.js';
29
+ import { call, Refusal } from './call.js';
23
30
  import { codebases } from './codebases.js';
24
31
  import { installations, repos as granted } from './github.js';
25
32
  import { assemble, canon, issues as merged, owners } from '../merge.js';
@@ -97,8 +104,42 @@ export function work(raw) {
97
104
  board: key,
98
105
  };
99
106
  }
107
+ /**
108
+ * What the board answers a caller with no seat in the org's made workspace yet,
109
+ * or an org with no namespace on the forge yet (cloud apps/task source.go): both
110
+ * are what opening the workspace makes. A seat refused for being no person's — an
111
+ * API key — is not one of them, and is said as it is.
112
+ */
113
+ const UNSEATED = /no forge identity for this principal yet|no namespace on the forge yet/i;
114
+ /** The workspace opened for a target, once while the page lives: concurrent reads share one open. */
115
+ const opened = new Map();
116
+ /** Set the org's code workspace up for the caller: its namespace, and their forge account and seat. Idempotent. */
117
+ export function open(t) {
118
+ const key = `${t.api}\n${t.org ?? ''}`;
119
+ let p = opened.get(key);
120
+ if (!p) {
121
+ p = call(t, 'POST', '/v1/git/workspace', {}).catch((e) => {
122
+ opened.delete(key);
123
+ throw e;
124
+ });
125
+ opened.set(key, p);
126
+ }
127
+ return p;
128
+ }
129
+ /** A board read that, refused for want of a seat or a namespace, opens the workspace and reads once more. */
130
+ async function seated(t, read) {
131
+ try {
132
+ return await read();
133
+ }
134
+ catch (e) {
135
+ if (!(e instanceof Refusal) || e.status !== 403 || !UNSEATED.test(e.message))
136
+ throw e;
137
+ await open(t);
138
+ return read();
139
+ }
140
+ }
100
141
  export async function boards(t, signal) {
101
- const raw = await call(t, 'GET', '/v1/task/projects', undefined, { signal });
142
+ const raw = await seated(t, () => call(t, 'GET', '/v1/task/projects', undefined, { signal }));
102
143
  return rows(raw)
103
144
  .map(board)
104
145
  .filter((b) => b !== null);
@@ -108,7 +149,7 @@ const issuesOf = (raw) => merged(rows(raw)
108
149
  .filter((w) => w !== null));
109
150
  /** Every issue and pull request the org has, from the forge and the task index, each once. */
110
151
  export async function everything(t, signal) {
111
- return issuesOf(await call(t, 'GET', '/v1/task/board', undefined, { signal }));
152
+ return issuesOf(await seated(t, () => call(t, 'GET', '/v1/task/board', undefined, { signal })));
112
153
  }
113
154
  /**
114
155
  * What `missing` calls each source. A reader that cannot stand without one — a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/build",
3
- "version": "0.2.125",
3
+ "version": "0.2.126",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "description": "Hanzo Build — say what you want, watch it built, deployed and running. The builder as a component, mounted by the Hanzo app at hanzo.ai.",