@r-33/opencode 0.4.7-rc.22 → 0.4.7-rc.24
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/cli/production-smoke/production-smoke.js +282 -618
- package/dist/index.js +450 -841
- package/dist/tui-entry/index.js +393 -901
- package/dist/v2-entry/index.js +449 -831
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -1,219 +1,22 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
constructor(code, options) {
|
|
4
|
-
super(
|
|
5
|
-
"Route 33 authorization failed",
|
|
6
|
-
options?.cause === void 0 ? void 0 : { cause: options.cause }
|
|
7
|
-
);
|
|
8
|
-
this.code = code;
|
|
9
|
-
this.name = "AuthError";
|
|
10
|
-
this.statusCode = options?.statusCode;
|
|
11
|
-
}
|
|
12
|
-
code;
|
|
13
|
-
statusCode;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// src/auth/build-authorize-url/build-authorize-url.ts
|
|
17
|
-
var buildAuthorizeUrl = (issuerUrl2, request) => {
|
|
18
|
-
const url = new URL("/authorize", issuerUrl2);
|
|
19
|
-
url.search = new URLSearchParams({
|
|
20
|
-
client_id: request.clientId,
|
|
21
|
-
code_challenge: request.codeChallenge,
|
|
22
|
-
code_challenge_method: "S256",
|
|
23
|
-
redirect_uri: request.redirectUri,
|
|
24
|
-
response_type: "code",
|
|
25
|
-
scope: request.scope,
|
|
26
|
-
state: request.state
|
|
27
|
-
}).toString();
|
|
28
|
-
return url;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// src/contract/adapters/contract-parse-error/contract-parse-error.ts
|
|
32
|
-
var ContractParseError = class extends Error {
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// src/contract/adapters/gateway-api-key/gateway-api-key.ts
|
|
36
|
-
var GatewayApiKey = class {
|
|
37
|
-
value;
|
|
38
|
-
constructor(value) {
|
|
39
|
-
this.value = value;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// src/contract/adapters/management-jwt/management-jwt.ts
|
|
44
|
-
var ManagementJwt = class {
|
|
45
|
-
value;
|
|
46
|
-
constructor(value) {
|
|
47
|
-
this.value = value;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// src/contract/adapters/parse-gateway-key/parse-gateway-key.ts
|
|
52
|
-
var parseGatewayKey = (value) => {
|
|
53
|
-
if (typeof value !== "string" || value.length === 0) {
|
|
54
|
-
throw new Error("gateway key must be non-empty");
|
|
55
|
-
}
|
|
56
|
-
return new GatewayApiKey(value);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// src/contract/adapters/parse-management-jwt/parse-management-jwt.ts
|
|
60
|
-
var parseManagementJwt = (value) => {
|
|
61
|
-
if (typeof value !== "string" || value.length === 0) {
|
|
62
|
-
throw new Error("management token must be non-empty");
|
|
63
|
-
}
|
|
64
|
-
return new ManagementJwt(value);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// src/contract/predicates/has-string-fields/has-string-fields.ts
|
|
68
|
-
var hasStringFields = (record, fields) => fields.every((field) => typeof record[field] === "string");
|
|
69
|
-
|
|
70
|
-
// src/contract/predicates/is-nullable-string/is-nullable-string.ts
|
|
71
|
-
var isNullableString = (value) => typeof value === "string" || value === null;
|
|
72
|
-
|
|
73
|
-
// src/contract/predicates/is-owner-type/is-owner-type.ts
|
|
74
|
-
var isOwnerType = (value) => value === "project" || value === "user_personal" || value === "user_project";
|
|
75
|
-
|
|
76
|
-
// src/contract/predicates/is-record/is-record.ts
|
|
77
|
-
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
78
|
-
|
|
79
|
-
// src/contract/adapters/parse-management-subject/parse-management-subject.ts
|
|
80
|
-
var parseManagementSubject = (credential) => {
|
|
81
|
-
const encodedPayload = credential.value.split(".")[1];
|
|
82
|
-
if (encodedPayload === void 0 || encodedPayload.length === 0) {
|
|
83
|
-
throw new ContractParseError("management token carries no usable subject");
|
|
84
|
-
}
|
|
85
|
-
let payload;
|
|
86
|
-
try {
|
|
87
|
-
payload = JSON.parse(
|
|
88
|
-
Buffer.from(encodedPayload, "base64url").toString("utf8")
|
|
89
|
-
);
|
|
90
|
-
} catch {
|
|
91
|
-
throw new ContractParseError("management token payload is not JSON");
|
|
92
|
-
}
|
|
93
|
-
if (!isRecord(payload)) {
|
|
94
|
-
throw new ContractParseError("management token payload is not an object");
|
|
95
|
-
}
|
|
96
|
-
const subject = payload["sub"];
|
|
97
|
-
if (typeof subject !== "string" || subject.length === 0) {
|
|
98
|
-
throw new ContractParseError("management token carries no usable subject");
|
|
99
|
-
}
|
|
100
|
-
return subject;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// src/contract/auth-session/parse-token-set/parse-token-set.ts
|
|
104
|
-
var parseTokenSet = (value) => {
|
|
105
|
-
if (!isRecord(value)) {
|
|
106
|
-
throw new ContractParseError("invalid token response");
|
|
107
|
-
}
|
|
108
|
-
if (typeof value["access_token"] !== "string" || typeof value["expires_in"] !== "number" || value["token_type"] !== "Bearer") {
|
|
109
|
-
throw new ContractParseError("invalid token response");
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
access_token: value["access_token"],
|
|
113
|
-
expires_in: value["expires_in"],
|
|
114
|
-
token_type: "Bearer",
|
|
115
|
-
...typeof value["id_token"] === "string" ? { id_token: value["id_token"] } : {},
|
|
116
|
-
...typeof value["refresh_token"] === "string" ? { refresh_token: value["refresh_token"] } : {},
|
|
117
|
-
...typeof value["scope"] === "string" ? { scope: value["scope"] } : {}
|
|
118
|
-
};
|
|
119
|
-
};
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createAuthSession as createAuthSession2 } from "@r-33/auth-browser";
|
|
120
3
|
|
|
121
|
-
// src/
|
|
122
|
-
var
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
code: options.input.code,
|
|
126
|
-
code_verifier: options.input.codeVerifier,
|
|
127
|
-
grant_type: "authorization_code",
|
|
128
|
-
redirect_uri: options.input.redirectUri
|
|
129
|
-
});
|
|
130
|
-
let response;
|
|
131
|
-
try {
|
|
132
|
-
response = await (options.fetchImpl ?? fetch)(options.tokenUrl, {
|
|
133
|
-
body,
|
|
134
|
-
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
135
|
-
method: "POST"
|
|
136
|
-
});
|
|
137
|
-
} catch (cause) {
|
|
138
|
-
throw new AuthError("AUTH_CODE_EXCHANGE_FAILED", { cause });
|
|
139
|
-
}
|
|
140
|
-
if (!response.ok) {
|
|
141
|
-
throw new AuthError("AUTH_CODE_EXCHANGE_FAILED", {
|
|
142
|
-
statusCode: response.status
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
let payload;
|
|
146
|
-
try {
|
|
147
|
-
payload = await response.json();
|
|
148
|
-
} catch (cause) {
|
|
149
|
-
throw new AuthError("AUTH_CODE_EXCHANGE_FAILED", { cause });
|
|
150
|
-
}
|
|
151
|
-
try {
|
|
152
|
-
return parseTokenSet(payload);
|
|
153
|
-
} catch (cause) {
|
|
154
|
-
if (cause instanceof ContractParseError) {
|
|
155
|
-
throw new AuthError("AUTH_CODE_EXCHANGE_FAILED", { cause });
|
|
156
|
-
}
|
|
157
|
-
throw cause;
|
|
158
|
-
}
|
|
4
|
+
// src/cli/read-env-base-url/read-env-base-url.ts
|
|
5
|
+
var readEnvBaseUrl = (env = process.env) => {
|
|
6
|
+
const value = env["ROUTE33_BASE_URL"]?.trim();
|
|
7
|
+
return value === "" ? void 0 : value;
|
|
159
8
|
};
|
|
160
9
|
|
|
161
|
-
// src/
|
|
162
|
-
var
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
grant_type: "refresh_token",
|
|
166
|
-
refresh_token: options.refreshToken
|
|
167
|
-
});
|
|
168
|
-
let response;
|
|
169
|
-
try {
|
|
170
|
-
response = await (options.fetchImpl ?? fetch)(options.tokenUrl, {
|
|
171
|
-
body,
|
|
172
|
-
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
173
|
-
method: "POST"
|
|
174
|
-
});
|
|
175
|
-
} catch (cause) {
|
|
176
|
-
throw new AuthError("AUTH_REAUTHENTICATION_REQUIRED", { cause });
|
|
177
|
-
}
|
|
178
|
-
if (!response.ok) {
|
|
179
|
-
throw new AuthError("AUTH_REAUTHENTICATION_REQUIRED", {
|
|
180
|
-
statusCode: response.status
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
let payload;
|
|
184
|
-
try {
|
|
185
|
-
payload = await response.json();
|
|
186
|
-
} catch (cause) {
|
|
187
|
-
throw new AuthError("AUTH_REAUTHENTICATION_REQUIRED", { cause });
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
return parseTokenSet(payload);
|
|
191
|
-
} catch (cause) {
|
|
192
|
-
if (cause instanceof ContractParseError) {
|
|
193
|
-
throw new AuthError("AUTH_REAUTHENTICATION_REQUIRED", { cause });
|
|
194
|
-
}
|
|
195
|
-
throw cause;
|
|
196
|
-
}
|
|
10
|
+
// src/cli/read-env-api-base/read-env-api-base.ts
|
|
11
|
+
var readEnvApiBase = (env = process.env) => {
|
|
12
|
+
const value = env["ROUTE33_API_BASE"]?.trim();
|
|
13
|
+
return value === "" ? void 0 : value;
|
|
197
14
|
};
|
|
198
15
|
|
|
199
|
-
// src/
|
|
200
|
-
var
|
|
201
|
-
const
|
|
202
|
-
return
|
|
203
|
-
authorizationUrl: (request) => buildAuthorizeUrl(options.issuerUrl, request),
|
|
204
|
-
exchangeCode: (input) => exchangeCodeAndParse({
|
|
205
|
-
clientId: options.clientId,
|
|
206
|
-
...options.fetchImpl === void 0 ? {} : { fetchImpl: options.fetchImpl },
|
|
207
|
-
input,
|
|
208
|
-
tokenUrl
|
|
209
|
-
}),
|
|
210
|
-
refresh: (refreshToken) => refreshSession({
|
|
211
|
-
clientId: options.clientId,
|
|
212
|
-
...options.fetchImpl === void 0 ? {} : { fetchImpl: options.fetchImpl },
|
|
213
|
-
refreshToken,
|
|
214
|
-
tokenUrl
|
|
215
|
-
})
|
|
216
|
-
};
|
|
16
|
+
// src/cli/read-env-auth-issuer/read-env-auth-issuer.ts
|
|
17
|
+
var readEnvAuthIssuer = (env = process.env) => {
|
|
18
|
+
const value = env["ROUTE33_AUTH_ISSUER"]?.trim();
|
|
19
|
+
return value === "" ? void 0 : value;
|
|
217
20
|
};
|
|
218
21
|
|
|
219
22
|
// src/shared/default-auth-issuer-url/default-auth-issuer-url.ts
|
|
@@ -261,260 +64,6 @@ var resolveCacheDir = (env) => {
|
|
|
261
64
|
);
|
|
262
65
|
};
|
|
263
66
|
|
|
264
|
-
// src/auth/open-browser-and-capture/open-browser-and-capture.ts
|
|
265
|
-
import { timingSafeEqual } from "node:crypto";
|
|
266
|
-
|
|
267
|
-
// src/auth/loopback-callback/loopback-callback.ts
|
|
268
|
-
import { createServer } from "node:http";
|
|
269
|
-
|
|
270
|
-
// src/auth/loopback-callback/callback-page/callback-page.ts
|
|
271
|
-
var MARK_PATHS = [
|
|
272
|
-
"M310.6,175.8c0-6.1-2.7-11.8-7.2-15.9l-127.6-114.4V7h-43.5v48.3c0,6.2,2.6,12.1,7.2,16.2l92.5,82.9H0v43.5h234.7l-95.6,91.4c-4.3,4.1-6.7,9.8-6.7,15.7v48.3h43.5v-39l128.1-122.4c4.4-4.2,6.8-10,6.7-16.1h0Z",
|
|
273
|
-
"M457.2,175.9v-2.6c18.4-4.9,33-14.1,44-27.7,11-13.6,16.5-30.3,16.5-50.3s-4.5-32.9-13.4-47.5c-9-14.5-21.6-26.1-38-34.9-16.4-8.7-35.8-13.1-58.3-13.1s-41.1,4-58.8,12.1-31.8,19.3-42.4,33.7-16.1,31-16.6,50h51.1c.3-10.8,3.6-20,9.8-27.7,6.2-7.6,14.2-13.5,24.1-17.5,9.9-4.1,20.6-6.1,32-6.1s22.3,2.2,31.1,6.7c8.8,4.5,15.6,10.8,20.5,18.8,4.9,8.1,7.3,17.5,7.3,28.4s-2.8,21.1-8.4,29.4-13.3,14.8-23.2,19.5-21.3,7.1-34.2,7.1h-29.9v43.3h29.9c16.2,0,30,2.5,41.5,7.5,11.5,5,20.2,12,26.1,21.1,6,9,9,19.4,9,31.2s-3,21.2-9.1,29.8-14.4,15.3-25.1,20.1c-10.7,4.9-22.9,7.3-36.7,7.3s-24.2-2.1-34.5-6.2-18.6-10-24.8-17.5c-6.3-7.5-9.8-16.5-10.6-26.8h-53.2c.6,19,6.3,35.7,17,50.2,10.7,14.5,25.2,25.7,43.6,33.8,18.4,8.1,39.4,12.1,63.1,12.1s45.1-4.4,63.7-13.2c18.6-8.8,33.3-20.8,44-36,10.8-15.2,16.1-32.5,16.1-51.8s-6.4-40.7-19.2-55.6c-12.8-14.9-30.8-24.2-54-27.8h0Z",
|
|
274
|
-
"M763,203.7c-12.8-14.9-30.8-24.2-54-27.8v-2.6c18.4-4.9,33-14.1,44-27.7,11-13.6,16.5-30.3,16.5-50.3s-4.5-32.9-13.4-47.5c-8.9-14.5-21.6-26.1-38-34.9-16.4-8.7-35.8-13.1-58.3-13.1s-41.1,4-58.8,12.1-31.8,19.3-42.4,33.7-16.1,31-16.6,50h51.1c.3-10.8,3.6-20,9.8-27.7,6.2-7.6,14.2-13.5,24.1-17.5,9.9-4.1,20.6-6.1,32-6.1s22.3,2.2,31.1,6.7c8.8,4.5,15.6,10.8,20.5,18.8,4.9,8.1,7.3,17.5,7.3,28.4s-2.8,21.1-8.4,29.4c-5.6,8.3-13.3,14.8-23.2,19.5s-21.3,7.1-34.2,7.1h-29.9v43.3h29.9c16.2,0,30,2.5,41.5,7.5,11.5,5,20.2,12,26.1,21.1,6,9,8.9,19.4,8.9,31.2s-3,21.2-9.1,29.8c-6.1,8.6-14.4,15.3-25.1,20.1-10.7,4.9-22.9,7.3-36.7,7.3s-24.2-2.1-34.5-6.2-18.6-10-24.8-17.5c-6.3-7.5-9.8-16.5-10.6-26.8h-53.2c.6,19,6.3,35.7,17,50.2,10.7,14.5,25.2,25.7,43.6,33.8,18.4,8.1,39.4,12.1,63.1,12.1s45.1-4.4,63.7-13.2,33.3-20.8,44-36c10.8-15.2,16.1-32.5,16.1-51.8s-6.4-40.7-19.2-55.6h0Z"
|
|
275
|
-
];
|
|
276
|
-
var BRAND_MARK = `<svg class="r33-mark" viewBox="0 0 782.2 360.3" fill="currentColor" role="img" aria-label="route33.ai" xmlns="http://www.w3.org/2000/svg"><path d="${MARK_PATHS[0]}"/><path d="${MARK_PATHS[1]}"/><path d="${MARK_PATHS[2]}"/></svg>`;
|
|
277
|
-
var PAGE_STYLE = `:root{color-scheme:dark;--r33-euro-blue:#0000FF;--r33-off-white:#F1F1F1;--r33-off-black:#121212;--r33-grey-300:#C9CBCF;--r33-radius-fillet:4px;--r33-space-2:8px;--r33-space-3:16px;--r33-space-4:24px;--r33-space-6:64px;--r33-font-body:"Geist","Helvetica Neue",Arial,sans-serif;--r33-font-mono:"Geist Mono","SFMono-Regular",Menlo,monospace;--r33-surface:var(--r33-off-black);--r33-text-primary:var(--r33-off-white);--r33-text-secondary:var(--r33-grey-300);--r33-fill-accent:var(--r33-euro-blue);--r33-on-fill-accent:var(--r33-off-white)}
|
|
278
|
-
*{box-sizing:border-box}
|
|
279
|
-
html,body{margin:0}
|
|
280
|
-
.r33-page{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:var(--r33-space-6);background:var(--r33-surface);color:var(--r33-text-primary);font-family:var(--r33-font-body);-webkit-font-smoothing:antialiased}
|
|
281
|
-
.r33-panel{display:grid;gap:var(--r33-space-4);max-width:460px;width:100%}
|
|
282
|
-
.r33-mark{height:40px;width:auto;color:var(--r33-text-primary)}
|
|
283
|
-
.r33-status{display:inline-flex;align-items:center;gap:var(--r33-space-2);font-size:11px;letter-spacing:0.08em;text-transform:uppercase;color:var(--r33-text-secondary)}
|
|
284
|
-
.r33-status__dot{width:8px;height:8px;background:var(--r33-fill-accent)}
|
|
285
|
-
.r33-status__dot--error{background:transparent;border:1px solid var(--r33-text-primary);border-radius:50%}
|
|
286
|
-
.r33-headline{margin:0;font-size:48px;line-height:0.85;letter-spacing:-0.02em;font-weight:600;color:var(--r33-text-primary);text-wrap:balance}
|
|
287
|
-
.r33-subline{margin:0;font-size:16px;line-height:1.45;color:var(--r33-text-secondary);max-width:40ch;text-wrap:pretty}
|
|
288
|
-
.r33-code{margin:0;font-size:13px;letter-spacing:0.04em;color:var(--r33-text-secondary)}
|
|
289
|
-
.r33-code__value{font-family:var(--r33-font-mono);text-transform:uppercase;color:var(--r33-text-primary)}
|
|
290
|
-
@media (prefers-reduced-motion:reduce){*{animation-duration:1ms!important;transition-duration:1ms!important}}`;
|
|
291
|
-
var buildCallbackPage = (state, errorCode) => {
|
|
292
|
-
const isError = state === "error";
|
|
293
|
-
const safeCode = (errorCode ?? "").replace(/[^a-z0-9_-]/gi, "");
|
|
294
|
-
const title = isError ? "Sign-in failed" : "Signed in";
|
|
295
|
-
const headline = isError ? "Sign-in failed" : "Signed in to route33";
|
|
296
|
-
const subline = isError ? "Return to OpenCode and retry." : "Return to OpenCode \u2014 one more step may wait there: if it asks which budget covers usage, pick a project. This window can be closed.";
|
|
297
|
-
const statusLabel = isError ? "Authentication error" : "Authenticated";
|
|
298
|
-
const dotClass = isError ? "r33-status__dot r33-status__dot--error" : "r33-status__dot";
|
|
299
|
-
const codeLine = isError && safeCode.length > 0 ? `<p class="r33-code">Error code: <span class="r33-code__value">${safeCode}</span></p>` : "";
|
|
300
|
-
return `<!doctype html>
|
|
301
|
-
<html lang="en" data-theme="dark">
|
|
302
|
-
<head>
|
|
303
|
-
<meta charset="utf-8">
|
|
304
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
305
|
-
<title>${title} \xB7 route33.ai</title>
|
|
306
|
-
<style>${PAGE_STYLE}</style>
|
|
307
|
-
</head>
|
|
308
|
-
<body>
|
|
309
|
-
<main class="r33-page">
|
|
310
|
-
<div class="r33-panel">
|
|
311
|
-
${BRAND_MARK}
|
|
312
|
-
<span class="r33-status"><span class="${dotClass}"></span>${statusLabel}</span>
|
|
313
|
-
<h1 class="r33-headline">${headline}</h1>
|
|
314
|
-
<p class="r33-subline">${subline}</p>
|
|
315
|
-
${codeLine}
|
|
316
|
-
</div>
|
|
317
|
-
</main>
|
|
318
|
-
</body>
|
|
319
|
-
</html>`;
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
// src/auth/loopback-callback/loopback-callback.ts
|
|
323
|
-
var createAuthLoopbackCallback = async () => {
|
|
324
|
-
let redirectUri = "http://127.0.0.1/callback";
|
|
325
|
-
let resolveCapture;
|
|
326
|
-
const captured = new Promise((resolve2) => {
|
|
327
|
-
resolveCapture = resolve2;
|
|
328
|
-
});
|
|
329
|
-
const server = createServer((request, response) => {
|
|
330
|
-
const url = new URL(request.url ?? "/", redirectUri);
|
|
331
|
-
if (request.method !== "GET" || url.pathname !== "/callback") {
|
|
332
|
-
response.writeHead(404).end();
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
const resolve2 = resolveCapture;
|
|
336
|
-
resolveCapture = void 0;
|
|
337
|
-
resolve2?.(url);
|
|
338
|
-
const error = url.searchParams.get("error");
|
|
339
|
-
const page = error === null || error.length === 0 ? buildCallbackPage("success") : buildCallbackPage("error", error);
|
|
340
|
-
response.writeHead(200, { "content-type": "text/html; charset=utf-8" });
|
|
341
|
-
response.end(page);
|
|
342
|
-
});
|
|
343
|
-
await new Promise((resolve2, reject) => {
|
|
344
|
-
const onError = (cause) => {
|
|
345
|
-
reject(new AuthError("AUTH_CALLBACK_LISTEN_FAILED", { cause }));
|
|
346
|
-
};
|
|
347
|
-
server.once("error", onError);
|
|
348
|
-
server.listen(0, "127.0.0.1", () => {
|
|
349
|
-
server.off("error", onError);
|
|
350
|
-
resolve2();
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
const address = server.address();
|
|
354
|
-
if (address === null || typeof address === "string") {
|
|
355
|
-
server.close();
|
|
356
|
-
throw new AuthError("AUTH_CALLBACK_LISTEN_FAILED");
|
|
357
|
-
}
|
|
358
|
-
redirectUri = `http://127.0.0.1:${String(address.port)}/callback`;
|
|
359
|
-
return {
|
|
360
|
-
redirectUri,
|
|
361
|
-
close: () => {
|
|
362
|
-
if (!server.listening) {
|
|
363
|
-
return Promise.resolve();
|
|
364
|
-
}
|
|
365
|
-
return new Promise((resolve2, reject) => {
|
|
366
|
-
server.close((cause) => {
|
|
367
|
-
if (cause === void 0) {
|
|
368
|
-
resolve2();
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
reject(new AuthError("AUTH_CALLBACK_CLEANUP_FAILED", { cause }));
|
|
372
|
-
});
|
|
373
|
-
});
|
|
374
|
-
},
|
|
375
|
-
wait: () => captured
|
|
376
|
-
};
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
// src/auth/open-system-browser/open-system-browser.ts
|
|
380
|
-
import { spawn } from "node:child_process";
|
|
381
|
-
var openSystemBrowser = async (url, options = {}) => new Promise((resolve2, reject) => {
|
|
382
|
-
let command = "xdg-open";
|
|
383
|
-
let args = [url.href];
|
|
384
|
-
if (process.platform === "darwin") {
|
|
385
|
-
command = "open";
|
|
386
|
-
} else if (process.platform === "win32") {
|
|
387
|
-
command = "cmd";
|
|
388
|
-
args = ["/c", "start", "", url.href];
|
|
389
|
-
}
|
|
390
|
-
if (options.spawnUrl !== void 0) {
|
|
391
|
-
options.spawnUrl(command, args, { detached: true, stdio: "ignore" });
|
|
392
|
-
resolve2();
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
const child = spawn(command, args, {
|
|
396
|
-
detached: true,
|
|
397
|
-
stdio: "ignore"
|
|
398
|
-
});
|
|
399
|
-
child.once("error", reject);
|
|
400
|
-
child.once("spawn", () => {
|
|
401
|
-
child.unref();
|
|
402
|
-
resolve2();
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
// src/auth/open-browser-and-capture/open-browser-and-capture.ts
|
|
407
|
-
var openBrowserAndCapture = async (options) => {
|
|
408
|
-
const callback = await createAuthLoopbackCallback();
|
|
409
|
-
const authorizationUrl = options.authorizationUrl(callback.redirectUri);
|
|
410
|
-
const browserRunner = options.browserRunner ?? ((url) => openSystemBrowser(url));
|
|
411
|
-
let timer;
|
|
412
|
-
const timeout = new Promise((_resolve, reject) => {
|
|
413
|
-
timer = setTimeout(() => {
|
|
414
|
-
reject(new AuthError("AUTH_CALLBACK_TIMEOUT"));
|
|
415
|
-
}, options.timeoutMs ?? 12e4);
|
|
416
|
-
});
|
|
417
|
-
const launch = browserRunner(authorizationUrl).catch((cause) => {
|
|
418
|
-
throw new AuthError("AUTH_BROWSER_LAUNCH_FAILED", { cause });
|
|
419
|
-
});
|
|
420
|
-
try {
|
|
421
|
-
const completed = await Promise.race([
|
|
422
|
-
Promise.all([launch, callback.wait()]),
|
|
423
|
-
timeout
|
|
424
|
-
]);
|
|
425
|
-
const callbackUrl = completed[1];
|
|
426
|
-
const actualState = callbackUrl.searchParams.get("state");
|
|
427
|
-
if (actualState === null) {
|
|
428
|
-
throw new AuthError("AUTH_CALLBACK_RESPONSE_INVALID");
|
|
429
|
-
}
|
|
430
|
-
const expectedState = Buffer.from(options.expectedState);
|
|
431
|
-
const receivedState = Buffer.from(actualState);
|
|
432
|
-
if (expectedState.length !== receivedState.length || !timingSafeEqual(expectedState, receivedState)) {
|
|
433
|
-
throw new AuthError("AUTH_CALLBACK_STATE_MISMATCH");
|
|
434
|
-
}
|
|
435
|
-
const code = callbackUrl.searchParams.get("code");
|
|
436
|
-
if (code === null || code.length === 0) {
|
|
437
|
-
throw new AuthError("AUTH_CALLBACK_RESPONSE_INVALID");
|
|
438
|
-
}
|
|
439
|
-
return { code, redirectUri: callback.redirectUri };
|
|
440
|
-
} finally {
|
|
441
|
-
if (timer !== void 0) {
|
|
442
|
-
clearTimeout(timer);
|
|
443
|
-
}
|
|
444
|
-
await callback.close();
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
// src/auth/pkce-verifier-and-challenge/pkce-verifier-and-challenge.ts
|
|
449
|
-
import { randomBytes } from "node:crypto";
|
|
450
|
-
|
|
451
|
-
// src/auth/pkce-challenge/pkce-challenge.ts
|
|
452
|
-
import { createHash } from "node:crypto";
|
|
453
|
-
var pkceChallenge = (verifier) => createHash("sha256").update(verifier).digest("base64url");
|
|
454
|
-
|
|
455
|
-
// src/auth/pkce-verifier-and-challenge/pkce-verifier-and-challenge.ts
|
|
456
|
-
var createPkceVerifierAndChallenge = () => {
|
|
457
|
-
const codeVerifier = randomBytes(32).toString("base64url");
|
|
458
|
-
return {
|
|
459
|
-
codeChallenge: pkceChallenge(codeVerifier),
|
|
460
|
-
codeVerifier,
|
|
461
|
-
state: randomBytes(32).toString("base64url")
|
|
462
|
-
};
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
// src/auth/requested-scopes/requested-scopes.ts
|
|
466
|
-
var REQUESTED_OAUTH_SCOPES = "openid offline_access orgs:read projects:read keys:read keys:write";
|
|
467
|
-
|
|
468
|
-
// src/auth/login-flow/login-flow.ts
|
|
469
|
-
var loginFlow = async (options) => {
|
|
470
|
-
const log = options.logger ?? logger;
|
|
471
|
-
log.info("auth.login.started");
|
|
472
|
-
const pkce = createPkceVerifierAndChallenge();
|
|
473
|
-
const captured = await openBrowserAndCapture({
|
|
474
|
-
authorizationUrl: (redirectUri) => options.session.authorizationUrl({
|
|
475
|
-
clientId: options.clientId,
|
|
476
|
-
codeChallenge: pkce.codeChallenge,
|
|
477
|
-
redirectUri,
|
|
478
|
-
scope: REQUESTED_OAUTH_SCOPES,
|
|
479
|
-
state: pkce.state
|
|
480
|
-
}),
|
|
481
|
-
...options.browserRunner === void 0 ? {} : { browserRunner: options.browserRunner },
|
|
482
|
-
expectedState: pkce.state,
|
|
483
|
-
...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
|
|
484
|
-
});
|
|
485
|
-
const tokenSet = await options.session.exchangeCode({
|
|
486
|
-
code: captured.code,
|
|
487
|
-
codeVerifier: pkce.codeVerifier,
|
|
488
|
-
redirectUri: captured.redirectUri
|
|
489
|
-
});
|
|
490
|
-
let credential;
|
|
491
|
-
try {
|
|
492
|
-
credential = parseManagementJwt(tokenSet.access_token);
|
|
493
|
-
} catch (cause) {
|
|
494
|
-
throw new AuthError("AUTH_TOKEN_RESPONSE_INVALID", { cause });
|
|
495
|
-
}
|
|
496
|
-
log.info("auth.login.completed");
|
|
497
|
-
return { credential, tokenSet };
|
|
498
|
-
};
|
|
499
|
-
|
|
500
|
-
// src/cli/read-env-base-url/read-env-base-url.ts
|
|
501
|
-
var readEnvBaseUrl = (env = process.env) => {
|
|
502
|
-
const value = env["ROUTE33_BASE_URL"]?.trim();
|
|
503
|
-
return value === "" ? void 0 : value;
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
// src/cli/read-env-api-base/read-env-api-base.ts
|
|
507
|
-
var readEnvApiBase = (env = process.env) => {
|
|
508
|
-
const value = env["ROUTE33_API_BASE"]?.trim();
|
|
509
|
-
return value === "" ? void 0 : value;
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
// src/cli/read-env-auth-issuer/read-env-auth-issuer.ts
|
|
513
|
-
var readEnvAuthIssuer = (env = process.env) => {
|
|
514
|
-
const value = env["ROUTE33_AUTH_ISSUER"]?.trim();
|
|
515
|
-
return value === "" ? void 0 : value;
|
|
516
|
-
};
|
|
517
|
-
|
|
518
67
|
// src/cli/read-env-cache-dir/read-env-cache-dir.ts
|
|
519
68
|
var readEnvCacheDir = (env = process.env) => resolveCacheDir(env);
|
|
520
69
|
|
|
@@ -596,6 +145,18 @@ var abortableSleep = (milliseconds, signal) => new Promise((resolve2, reject) =>
|
|
|
596
145
|
// src/config/is-resendable-body/is-resendable-body.ts
|
|
597
146
|
var isResendableBody = (body) => body === void 0 || typeof body === "string" || body instanceof ArrayBuffer || ArrayBuffer.isView(body) || body instanceof Blob || body instanceof URLSearchParams || body instanceof FormData;
|
|
598
147
|
|
|
148
|
+
// src/contract/predicates/has-string-fields/has-string-fields.ts
|
|
149
|
+
var hasStringFields = (record, fields) => fields.every((field) => typeof record[field] === "string");
|
|
150
|
+
|
|
151
|
+
// src/contract/predicates/is-nullable-string/is-nullable-string.ts
|
|
152
|
+
var isNullableString = (value) => typeof value === "string" || value === null;
|
|
153
|
+
|
|
154
|
+
// src/contract/predicates/is-owner-type/is-owner-type.ts
|
|
155
|
+
var isOwnerType = (value) => value === "project" || value === "user_personal" || value === "user_project";
|
|
156
|
+
|
|
157
|
+
// src/contract/predicates/is-record/is-record.ts
|
|
158
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
159
|
+
|
|
599
160
|
// src/config/parse-exhaustion-envelope/parse-exhaustion-envelope.ts
|
|
600
161
|
var parseExhaustionEnvelope = async (response) => {
|
|
601
162
|
let body;
|
|
@@ -885,8 +446,8 @@ var catalogMemory = /* @__PURE__ */ new Map();
|
|
|
885
446
|
var CATALOG_CACHE_VERSION = 2;
|
|
886
447
|
|
|
887
448
|
// src/catalog/catalog-cache/hash-key/hash-key.ts
|
|
888
|
-
import { createHash
|
|
889
|
-
var hashKey = (baseURL, gatewayKey) =>
|
|
449
|
+
import { createHash } from "node:crypto";
|
|
450
|
+
var hashKey = (baseURL, gatewayKey) => createHash("sha256").update(`${baseURL}
|
|
890
451
|
${gatewayKey.value}`).digest("hex").slice(0, 12);
|
|
891
452
|
|
|
892
453
|
// src/catalog/catalog-cache/is-catalog-model-record/is-catalog-model-record.ts
|
|
@@ -984,12 +545,72 @@ var catalogModelsUrl = (baseURL) => {
|
|
|
984
545
|
while (normalizedBaseURL.endsWith("/")) {
|
|
985
546
|
normalizedBaseURL = normalizedBaseURL.slice(0, -1);
|
|
986
547
|
}
|
|
987
|
-
return `${normalizedBaseURL}/models`;
|
|
548
|
+
return `${normalizedBaseURL}/models`;
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
// src/catalog/default-fetch-timeout-ms/default-fetch-timeout-ms.ts
|
|
552
|
+
var DEFAULT_FETCH_TIMEOUT_MS = 5e3;
|
|
553
|
+
|
|
554
|
+
// src/contract/adapters/contract-parse-error/contract-parse-error.ts
|
|
555
|
+
var ContractParseError = class extends Error {
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
// src/contract/adapters/gateway-api-key/gateway-api-key.ts
|
|
559
|
+
var GatewayApiKey = class {
|
|
560
|
+
value;
|
|
561
|
+
constructor(value) {
|
|
562
|
+
this.value = value;
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
// src/contract/adapters/management-jwt/management-jwt.ts
|
|
567
|
+
var ManagementJwt = class {
|
|
568
|
+
value;
|
|
569
|
+
constructor(value) {
|
|
570
|
+
this.value = value;
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
// src/contract/adapters/parse-gateway-key/parse-gateway-key.ts
|
|
575
|
+
var parseGatewayKey = (value) => {
|
|
576
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
577
|
+
throw new Error("gateway key must be non-empty");
|
|
578
|
+
}
|
|
579
|
+
return new GatewayApiKey(value);
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
// src/contract/adapters/parse-management-jwt/parse-management-jwt.ts
|
|
583
|
+
var parseManagementJwt = (value) => {
|
|
584
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
585
|
+
throw new Error("management token must be non-empty");
|
|
586
|
+
}
|
|
587
|
+
return new ManagementJwt(value);
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
// src/contract/adapters/parse-management-subject/parse-management-subject.ts
|
|
591
|
+
var parseManagementSubject = (credential) => {
|
|
592
|
+
const encodedPayload = credential.value.split(".")[1];
|
|
593
|
+
if (encodedPayload === void 0 || encodedPayload.length === 0) {
|
|
594
|
+
throw new ContractParseError("management token carries no usable subject");
|
|
595
|
+
}
|
|
596
|
+
let payload;
|
|
597
|
+
try {
|
|
598
|
+
payload = JSON.parse(
|
|
599
|
+
Buffer.from(encodedPayload, "base64url").toString("utf8")
|
|
600
|
+
);
|
|
601
|
+
} catch {
|
|
602
|
+
throw new ContractParseError("management token payload is not JSON");
|
|
603
|
+
}
|
|
604
|
+
if (!isRecord(payload)) {
|
|
605
|
+
throw new ContractParseError("management token payload is not an object");
|
|
606
|
+
}
|
|
607
|
+
const subject = payload["sub"];
|
|
608
|
+
if (typeof subject !== "string" || subject.length === 0) {
|
|
609
|
+
throw new ContractParseError("management token carries no usable subject");
|
|
610
|
+
}
|
|
611
|
+
return subject;
|
|
988
612
|
};
|
|
989
613
|
|
|
990
|
-
// src/catalog/default-fetch-timeout-ms/default-fetch-timeout-ms.ts
|
|
991
|
-
var DEFAULT_FETCH_TIMEOUT_MS = 5e3;
|
|
992
|
-
|
|
993
614
|
// src/contract/gateway-catalog/parse-catalog-result/parse-catalog-result.ts
|
|
994
615
|
var parseCatalogResult = (value) => {
|
|
995
616
|
if (!isRecord(value) || !Array.isArray(value["data"])) {
|
|
@@ -2978,7 +2599,7 @@ var createLeaseInstallationFactory = (options) => {
|
|
|
2978
2599
|
};
|
|
2979
2600
|
|
|
2980
2601
|
// src/key-lease/scope-id/scope-id.ts
|
|
2981
|
-
import { createHash as
|
|
2602
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
2982
2603
|
var deriveScopeId = (input) => {
|
|
2983
2604
|
let identity;
|
|
2984
2605
|
switch (input.attribution.kind) {
|
|
@@ -3001,7 +2622,7 @@ var deriveScopeId = (input) => {
|
|
|
3001
2622
|
throw new TypeError(`Unexpected attribution: ${String(unexpected)}`);
|
|
3002
2623
|
}
|
|
3003
2624
|
}
|
|
3004
|
-
return
|
|
2625
|
+
return createHash2("sha256").update(JSON.stringify(identity)).digest("hex");
|
|
3005
2626
|
};
|
|
3006
2627
|
|
|
3007
2628
|
// src/requested-client-id/requested-client-id.ts
|
|
@@ -3116,6 +2737,47 @@ var TRUSTED_PARTY_COPY = {
|
|
|
3116
2737
|
title: "Connect Route 33"
|
|
3117
2738
|
};
|
|
3118
2739
|
|
|
2740
|
+
// src/ux/callback-page-copy/callback-page-copy.ts
|
|
2741
|
+
var CALLBACK_PAGE_COPY = {
|
|
2742
|
+
errorHeadline: "Sign-in failed",
|
|
2743
|
+
errorSubline: "Return to OpenCode and retry.",
|
|
2744
|
+
successHeadline: "Signed in to route33",
|
|
2745
|
+
successSubline: "Return to OpenCode \u2014 one more step may wait there: if it asks which budget covers usage, pick a project. This window can be closed."
|
|
2746
|
+
};
|
|
2747
|
+
|
|
2748
|
+
// src/route33-runtime/login-session/login-session.ts
|
|
2749
|
+
import { AuthError as AuthError2 } from "@r-33/auth-browser";
|
|
2750
|
+
|
|
2751
|
+
// src/route33-login/route33-login.ts
|
|
2752
|
+
import {
|
|
2753
|
+
AuthError,
|
|
2754
|
+
loginFlow
|
|
2755
|
+
} from "@r-33/auth-browser";
|
|
2756
|
+
|
|
2757
|
+
// src/requested-scopes/requested-scopes.ts
|
|
2758
|
+
var REQUESTED_OAUTH_SCOPES = "openid offline_access orgs:read projects:read users:read keys:read keys:write";
|
|
2759
|
+
|
|
2760
|
+
// src/route33-login/route33-login.ts
|
|
2761
|
+
var route33Login = async (options) => {
|
|
2762
|
+
const log = options.logger ?? logger;
|
|
2763
|
+
const tokenSet = await loginFlow({
|
|
2764
|
+
...options.browserRunner === void 0 ? {} : { browserRunner: options.browserRunner },
|
|
2765
|
+
clientId: options.clientId,
|
|
2766
|
+
logger: log,
|
|
2767
|
+
pageCopy: CALLBACK_PAGE_COPY,
|
|
2768
|
+
scope: REQUESTED_OAUTH_SCOPES,
|
|
2769
|
+
session: options.session,
|
|
2770
|
+
...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
|
|
2771
|
+
});
|
|
2772
|
+
let credential;
|
|
2773
|
+
try {
|
|
2774
|
+
credential = parseManagementJwt(tokenSet.access_token);
|
|
2775
|
+
} catch (cause) {
|
|
2776
|
+
throw new AuthError("AUTH_TOKEN_RESPONSE_INVALID", { cause });
|
|
2777
|
+
}
|
|
2778
|
+
return { credential, tokenSet };
|
|
2779
|
+
};
|
|
2780
|
+
|
|
3119
2781
|
// src/route33-runtime/login-session/login-session.ts
|
|
3120
2782
|
var EXPIRY_SKEW_MS = 6e4;
|
|
3121
2783
|
var LoginSession = class {
|
|
@@ -3125,15 +2787,11 @@ var LoginSession = class {
|
|
|
3125
2787
|
constructor(options) {
|
|
3126
2788
|
this.#options = options;
|
|
3127
2789
|
}
|
|
3128
|
-
/**
|
|
3129
|
-
* Resolves the login once per process, sharing in-flight attempts.
|
|
3130
|
-
* @param policy - Whether this attempt may start a browser login; an in-flight attempt is always shared.
|
|
3131
|
-
* @returns The token set plus its typed management credential.
|
|
3132
|
-
*/
|
|
3133
2790
|
/**
|
|
3134
2791
|
* Clears the session: the cached login result and the stored refresh
|
|
3135
2792
|
* token. The next login starts from scratch — /r33 logout and the
|
|
3136
2793
|
* auto-reconnect path both land here.
|
|
2794
|
+
* @returns Resolved once the session and the stored refresh token are gone.
|
|
3137
2795
|
*/
|
|
3138
2796
|
async clear() {
|
|
3139
2797
|
this.#result = void 0;
|
|
@@ -3141,8 +2799,9 @@ var LoginSession = class {
|
|
|
3141
2799
|
await this.#options.tokenStore?.set(void 0);
|
|
3142
2800
|
}
|
|
3143
2801
|
/**
|
|
3144
|
-
*
|
|
3145
|
-
* @param policy
|
|
2802
|
+
* Resolves the login once per process, sharing in-flight attempts.
|
|
2803
|
+
* @param policy - Whether this attempt may start a browser login; an in-flight attempt is always shared.
|
|
2804
|
+
* @returns The token set plus its typed management credential.
|
|
3146
2805
|
*/
|
|
3147
2806
|
result(policy = {}) {
|
|
3148
2807
|
if (this.#result !== void 0 && this.#expiresAt !== void 0 && Date.now() >= this.#expiresAt - EXPIRY_SKEW_MS) {
|
|
@@ -3168,10 +2827,10 @@ var LoginSession = class {
|
|
|
3168
2827
|
return viaRefresh;
|
|
3169
2828
|
}
|
|
3170
2829
|
if (policy.allowBrowser === false) {
|
|
3171
|
-
throw new
|
|
2830
|
+
throw new AuthError2("AUTH_REAUTHENTICATION_REQUIRED");
|
|
3172
2831
|
}
|
|
3173
2832
|
await this.#options.presenter?.present(TRUSTED_PARTY_COPY);
|
|
3174
|
-
const result = await
|
|
2833
|
+
const result = await route33Login(this.#options.auth);
|
|
3175
2834
|
this.#trackExpiry(result.tokenSet.expires_in);
|
|
3176
2835
|
await this.#persist(result.tokenSet.refresh_token);
|
|
3177
2836
|
return result;
|
|
@@ -3185,23 +2844,29 @@ var LoginSession = class {
|
|
|
3185
2844
|
if (stored === void 0 || stored === "") {
|
|
3186
2845
|
return void 0;
|
|
3187
2846
|
}
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
tokenSet = await this.#options.auth.session.refresh(stored);
|
|
3191
|
-
} catch {
|
|
3192
|
-
logger.info("auth.refresh.fell-back-to-browser");
|
|
2847
|
+
const tokenSet = await this.#tryRefreshToken(stored);
|
|
2848
|
+
if (tokenSet === void 0) {
|
|
3193
2849
|
return void 0;
|
|
3194
2850
|
}
|
|
3195
2851
|
let credential;
|
|
3196
2852
|
try {
|
|
3197
2853
|
credential = parseManagementJwt(tokenSet.access_token);
|
|
3198
2854
|
} catch (cause) {
|
|
3199
|
-
throw new
|
|
2855
|
+
throw new AuthError2("AUTH_TOKEN_RESPONSE_INVALID", { cause });
|
|
3200
2856
|
}
|
|
3201
2857
|
this.#trackExpiry(tokenSet.expires_in);
|
|
3202
2858
|
await this.#persist(tokenSet.refresh_token);
|
|
3203
2859
|
return { credential, tokenSet };
|
|
3204
2860
|
}
|
|
2861
|
+
async #tryRefreshToken(stored) {
|
|
2862
|
+
const session = this.#options.auth.session;
|
|
2863
|
+
try {
|
|
2864
|
+
return await session.refresh(stored);
|
|
2865
|
+
} catch {
|
|
2866
|
+
logger.info("auth.refresh.fell-back-to-browser");
|
|
2867
|
+
return void 0;
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
3205
2870
|
#trackExpiry(expiresIn) {
|
|
3206
2871
|
this.#expiresAt = Date.now() + expiresIn * 1e3;
|
|
3207
2872
|
}
|
|
@@ -3235,6 +2900,53 @@ var Route33Runtime = class {
|
|
|
3235
2900
|
login(policy = {}) {
|
|
3236
2901
|
return this.#session.result(policy);
|
|
3237
2902
|
}
|
|
2903
|
+
/**
|
|
2904
|
+
* Lists exactly the projects the current management login can mint keys
|
|
2905
|
+
* on: the login's per-user budget rows intersected with the
|
|
2906
|
+
* member-visible project listing, organisation names stitched from the
|
|
2907
|
+
* login's own memberships. Orgs the login merely administers carry no
|
|
2908
|
+
* budget row and drop out — the picker never offers a project whose
|
|
2909
|
+
* keys the login cannot create.
|
|
2910
|
+
* @returns Mintable projects with organisation context for the picker.
|
|
2911
|
+
*/
|
|
2912
|
+
async listMintableProjects() {
|
|
2913
|
+
const credential = await this.#session.credential();
|
|
2914
|
+
const subject = this.#subject(credential);
|
|
2915
|
+
const client = this.#client();
|
|
2916
|
+
const [budgets, memberships] = await Promise.all([
|
|
2917
|
+
client.listProjectBudgets(credential, subject),
|
|
2918
|
+
client.listMemberships(credential, subject)
|
|
2919
|
+
]);
|
|
2920
|
+
const organisationNames = new Map(
|
|
2921
|
+
memberships.org_memberships.map(({ org_id, org_name }) => [
|
|
2922
|
+
org_id,
|
|
2923
|
+
org_name
|
|
2924
|
+
])
|
|
2925
|
+
);
|
|
2926
|
+
const listings = await Promise.all(
|
|
2927
|
+
[...new Set(budgets.data.map(({ org_id }) => org_id))].map(
|
|
2928
|
+
(orgId) => client.listProjects(credential, orgId)
|
|
2929
|
+
)
|
|
2930
|
+
);
|
|
2931
|
+
const projectsById = new Map(
|
|
2932
|
+
listings.flatMap(({ data }) => data).map((project) => [project.id, project])
|
|
2933
|
+
);
|
|
2934
|
+
return budgets.data.flatMap(({ org_id, project_id }) => {
|
|
2935
|
+
const project = projectsById.get(project_id);
|
|
2936
|
+
if (project === void 0) {
|
|
2937
|
+
return [];
|
|
2938
|
+
}
|
|
2939
|
+
return [
|
|
2940
|
+
{
|
|
2941
|
+
...project,
|
|
2942
|
+
organisation: {
|
|
2943
|
+
id: org_id,
|
|
2944
|
+
name: organisationNames.get(org_id) ?? org_id
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2947
|
+
];
|
|
2948
|
+
});
|
|
2949
|
+
}
|
|
3238
2950
|
/**
|
|
3239
2951
|
* Lists projects visible to the current management login.
|
|
3240
2952
|
* @returns Projects with their listing organisation stitched in.
|
|
@@ -3474,7 +3186,7 @@ var Route33Runtime = class {
|
|
|
3474
3186
|
return resolveAttribution({
|
|
3475
3187
|
loadProjects: async () => {
|
|
3476
3188
|
await this.#session.credential();
|
|
3477
|
-
return this.
|
|
3189
|
+
return this.listMintableProjects();
|
|
3478
3190
|
},
|
|
3479
3191
|
...this.#options.presenter === void 0 ? {} : { presenter: this.#options.presenter },
|
|
3480
3192
|
state: this.#options.state
|
|
@@ -3638,6 +3350,43 @@ var createRoute33Plugin = (options = {}) => {
|
|
|
3638
3350
|
};
|
|
3639
3351
|
};
|
|
3640
3352
|
|
|
3353
|
+
// src/production-runtime-options/production-runtime-options.ts
|
|
3354
|
+
import { createAuthSession } from "@r-33/auth-browser";
|
|
3355
|
+
|
|
3356
|
+
// src/management/drain-pages/drain-pages.ts
|
|
3357
|
+
var drainPages = async (fetchPage) => {
|
|
3358
|
+
const first = await fetchPage("");
|
|
3359
|
+
const data = [...first.data];
|
|
3360
|
+
let { page } = first;
|
|
3361
|
+
while (page.has_more && page.next_cursor !== null) {
|
|
3362
|
+
const next = await fetchPage(page.next_cursor);
|
|
3363
|
+
data.push(...next.data);
|
|
3364
|
+
({ page } = next);
|
|
3365
|
+
}
|
|
3366
|
+
return { data, page: { ...page, has_more: false, next_cursor: null } };
|
|
3367
|
+
};
|
|
3368
|
+
|
|
3369
|
+
// src/management/management-error/management-error.ts
|
|
3370
|
+
var ManagementError = class extends Error {
|
|
3371
|
+
constructor(code, options) {
|
|
3372
|
+
super(
|
|
3373
|
+
"Route 33 management request failed",
|
|
3374
|
+
options?.cause === void 0 ? void 0 : { cause: "Route 33 management dependency failed" }
|
|
3375
|
+
);
|
|
3376
|
+
this.code = code;
|
|
3377
|
+
this.name = "ManagementError";
|
|
3378
|
+
this.statusCode = options?.statusCode;
|
|
3379
|
+
}
|
|
3380
|
+
code;
|
|
3381
|
+
statusCode;
|
|
3382
|
+
};
|
|
3383
|
+
|
|
3384
|
+
// src/management/sdk-management-keys/sdk-management-keys.ts
|
|
3385
|
+
import {
|
|
3386
|
+
createRoute33Client,
|
|
3387
|
+
Route33SdkError
|
|
3388
|
+
} from "@r-33/sdk";
|
|
3389
|
+
|
|
3641
3390
|
// src/contract/management-keys/parse-api-key/parse-api-key.ts
|
|
3642
3391
|
var parseApiKey = (value) => {
|
|
3643
3392
|
if (!isRecord(value) || !isOwnerType(value["ownership_type"]) || !isNullableString(value["project_id"])) {
|
|
@@ -3799,6 +3548,39 @@ var parseOrganization = (value) => {
|
|
|
3799
3548
|
};
|
|
3800
3549
|
};
|
|
3801
3550
|
|
|
3551
|
+
// src/contract/management-keys/parse-project-budget-state/parse-project-budget-state.ts
|
|
3552
|
+
var parseProjectBudgetState = (value) => {
|
|
3553
|
+
if (!isRecord(value)) {
|
|
3554
|
+
throw new ContractParseError("invalid project budget");
|
|
3555
|
+
}
|
|
3556
|
+
const stringField = (name) => {
|
|
3557
|
+
const field = value[name];
|
|
3558
|
+
if (typeof field !== "string") {
|
|
3559
|
+
throw new ContractParseError("invalid project budget");
|
|
3560
|
+
}
|
|
3561
|
+
return field;
|
|
3562
|
+
};
|
|
3563
|
+
const cap = value["cap"];
|
|
3564
|
+
if (typeof cap !== "number") {
|
|
3565
|
+
throw new ContractParseError("invalid project budget");
|
|
3566
|
+
}
|
|
3567
|
+
const hasUsage = value["has_usage"];
|
|
3568
|
+
if (typeof hasUsage !== "boolean") {
|
|
3569
|
+
throw new ContractParseError("invalid project budget");
|
|
3570
|
+
}
|
|
3571
|
+
const source = value["source"];
|
|
3572
|
+
if (source !== "own_cap" && source !== "project_default" && source !== "org_default" && source !== "tenant_default" && source !== "platform_default") {
|
|
3573
|
+
throw new ContractParseError("invalid project budget");
|
|
3574
|
+
}
|
|
3575
|
+
return {
|
|
3576
|
+
cap,
|
|
3577
|
+
has_usage: hasUsage,
|
|
3578
|
+
org_id: stringField("org_id"),
|
|
3579
|
+
project_id: stringField("project_id"),
|
|
3580
|
+
source
|
|
3581
|
+
};
|
|
3582
|
+
};
|
|
3583
|
+
|
|
3802
3584
|
// src/contract/management-keys/parse-wire-money/parse-wire-money.ts
|
|
3803
3585
|
var parseWireMoney = (value) => {
|
|
3804
3586
|
if (!isRecord(value)) return null;
|
|
@@ -3821,266 +3603,185 @@ var parseProject = (value) => {
|
|
|
3821
3603
|
};
|
|
3822
3604
|
};
|
|
3823
3605
|
|
|
3824
|
-
// src/
|
|
3825
|
-
var
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
"Route 33 management request failed",
|
|
3829
|
-
options?.cause === void 0 ? void 0 : { cause: "Route 33 management dependency failed" }
|
|
3830
|
-
);
|
|
3831
|
-
this.code = code;
|
|
3832
|
-
this.name = "ManagementError";
|
|
3833
|
-
this.statusCode = options?.statusCode;
|
|
3606
|
+
// src/contract/management-keys/parse-user-memberships/parse-user-memberships.ts
|
|
3607
|
+
var parseUserMemberships = (value) => {
|
|
3608
|
+
if (!isRecord(value)) {
|
|
3609
|
+
throw new ContractParseError("invalid user memberships");
|
|
3834
3610
|
}
|
|
3835
|
-
|
|
3836
|
-
|
|
3611
|
+
const rows = value["org_memberships"];
|
|
3612
|
+
if (!Array.isArray(rows)) {
|
|
3613
|
+
throw new ContractParseError("invalid user memberships");
|
|
3614
|
+
}
|
|
3615
|
+
return {
|
|
3616
|
+
org_memberships: rows.map((row) => {
|
|
3617
|
+
if (!isRecord(row)) {
|
|
3618
|
+
throw new ContractParseError("invalid user memberships");
|
|
3619
|
+
}
|
|
3620
|
+
const orgId = row["org_id"];
|
|
3621
|
+
const orgName = row["org_name"];
|
|
3622
|
+
if (typeof orgId !== "string" || typeof orgName !== "string") {
|
|
3623
|
+
throw new ContractParseError("invalid user memberships");
|
|
3624
|
+
}
|
|
3625
|
+
return { org_id: orgId, org_name: orgName };
|
|
3626
|
+
})
|
|
3627
|
+
};
|
|
3837
3628
|
};
|
|
3838
3629
|
|
|
3839
|
-
// src/management/management-
|
|
3840
|
-
var
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
return await response.json();
|
|
3862
|
-
} catch (cause) {
|
|
3863
|
-
throw new ContractParseError("invalid management response", { cause });
|
|
3864
|
-
}
|
|
3865
|
-
});
|
|
3866
|
-
}
|
|
3867
|
-
/** Sends a request whose successful response has no body.
|
|
3868
|
-
* @param request - Management path and method.
|
|
3869
|
-
*/
|
|
3870
|
-
empty(request) {
|
|
3871
|
-
return this.#perform(request, () => Promise.resolve());
|
|
3872
|
-
}
|
|
3873
|
-
async #perform(request, consume) {
|
|
3874
|
-
const controller = new AbortController();
|
|
3875
|
-
const timer = setTimeout(() => {
|
|
3876
|
-
controller.abort();
|
|
3877
|
-
}, this.#timeoutMs);
|
|
3878
|
-
const headers = new Headers({
|
|
3879
|
-
accept: "application/json",
|
|
3880
|
-
authorization: `Bearer ${this.#credential.value}`
|
|
3630
|
+
// src/management/sdk-management-keys/sdk-management-keys.ts
|
|
3631
|
+
var API_PREFIX_PATTERN = /\/api\/v1\/?$/;
|
|
3632
|
+
var sdkManagementKeys = (options) => {
|
|
3633
|
+
const baseUrl = options.apiBaseUrl.replace(API_PREFIX_PATTERN, "");
|
|
3634
|
+
const timeoutMs = options.timeoutMs ?? 1e4;
|
|
3635
|
+
const fetchImpl = options.fetchImpl;
|
|
3636
|
+
const observingFetch = (status) => fetchImpl === void 0 ? void 0 : async (input, init) => {
|
|
3637
|
+
const response = await fetchImpl(input, init);
|
|
3638
|
+
status.code = response.status;
|
|
3639
|
+
return response;
|
|
3640
|
+
};
|
|
3641
|
+
const callClient = (accessToken, status) => {
|
|
3642
|
+
const provider = {
|
|
3643
|
+
getToken: () => Promise.resolve(accessToken.value),
|
|
3644
|
+
onUnauthorized: () => Promise.resolve(accessToken.value)
|
|
3645
|
+
};
|
|
3646
|
+
const observedFetch = observingFetch(status);
|
|
3647
|
+
return createRoute33Client({
|
|
3648
|
+
baseUrl,
|
|
3649
|
+
provider,
|
|
3650
|
+
timeoutMs,
|
|
3651
|
+
...observedFetch === void 0 ? {} : { fetch: observedFetch }
|
|
3881
3652
|
});
|
|
3882
|
-
|
|
3883
|
-
|
|
3653
|
+
};
|
|
3654
|
+
const mapFailure = (cause) => {
|
|
3655
|
+
if (cause instanceof ManagementError || cause instanceof ContractParseError) {
|
|
3656
|
+
return cause;
|
|
3657
|
+
}
|
|
3658
|
+
if (cause instanceof Route33SdkError) {
|
|
3659
|
+
const code = cause.code === "SDK_TIMEOUT" ? "MANAGEMENT_TIMEOUT" : "MANAGEMENT_NETWORK_ERROR";
|
|
3660
|
+
return new ManagementError(code, { cause });
|
|
3661
|
+
}
|
|
3662
|
+
if (cause instanceof SyntaxError) {
|
|
3663
|
+
return new ContractParseError("invalid management response", { cause });
|
|
3884
3664
|
}
|
|
3665
|
+
return new ManagementError("MANAGEMENT_NETWORK_ERROR", { cause });
|
|
3666
|
+
};
|
|
3667
|
+
const call = async (accessToken, run) => {
|
|
3668
|
+
const status = { code: void 0 };
|
|
3885
3669
|
try {
|
|
3886
|
-
const
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
method: request.method,
|
|
3890
|
-
signal: controller.signal
|
|
3891
|
-
});
|
|
3892
|
-
let response = await send();
|
|
3893
|
-
if (response.status === 401 && this.#onUnauthorized !== void 0) {
|
|
3894
|
-
await this.#onUnauthorized();
|
|
3895
|
-
response = await send();
|
|
3896
|
-
}
|
|
3897
|
-
if (!response.ok) {
|
|
3670
|
+
const outcome = await run(callClient(accessToken, status));
|
|
3671
|
+
const code = status.code;
|
|
3672
|
+
if (code === void 0 || code < 200 || code >= 300) {
|
|
3898
3673
|
throw new ManagementError(
|
|
3899
|
-
|
|
3900
|
-
{ statusCode:
|
|
3674
|
+
code === 401 ? "MANAGEMENT_UNAUTHORIZED" : "MANAGEMENT_HTTP_ERROR",
|
|
3675
|
+
{ statusCode: code }
|
|
3901
3676
|
);
|
|
3902
3677
|
}
|
|
3903
|
-
return
|
|
3678
|
+
return outcome.data;
|
|
3904
3679
|
} catch (cause) {
|
|
3905
|
-
|
|
3906
|
-
throw cause;
|
|
3907
|
-
}
|
|
3908
|
-
if (controller.signal.aborted) {
|
|
3909
|
-
throw new ManagementError("MANAGEMENT_TIMEOUT", { cause });
|
|
3910
|
-
}
|
|
3911
|
-
if (cause instanceof ContractParseError) {
|
|
3912
|
-
throw cause;
|
|
3913
|
-
}
|
|
3914
|
-
throw new ManagementError("MANAGEMENT_NETWORK_ERROR", { cause });
|
|
3915
|
-
} finally {
|
|
3916
|
-
clearTimeout(timer);
|
|
3680
|
+
throw mapFailure(cause);
|
|
3917
3681
|
}
|
|
3918
|
-
}
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
*/
|
|
3957
|
-
async delete(accessToken, id) {
|
|
3958
|
-
this.#authorize(accessToken);
|
|
3959
|
-
await this.#transport.empty({
|
|
3960
|
-
method: "DELETE",
|
|
3961
|
-
path: `api-keys/${encodeURIComponent(id)}`
|
|
3962
|
-
});
|
|
3963
|
-
}
|
|
3964
|
-
/** Gets a safe key DTO.
|
|
3965
|
-
* @param accessToken - Credential required by the frozen contract.
|
|
3966
|
-
* @param id - Key identifier.
|
|
3967
|
-
* @returns The secret-free key DTO.
|
|
3968
|
-
*/
|
|
3969
|
-
async get(accessToken, id) {
|
|
3970
|
-
this.#authorize(accessToken);
|
|
3971
|
-
return parseApiKey(
|
|
3972
|
-
await this.#transport.json({
|
|
3973
|
-
method: "GET",
|
|
3974
|
-
path: `api-keys/${encodeURIComponent(id)}`
|
|
3975
|
-
})
|
|
3976
|
-
);
|
|
3977
|
-
}
|
|
3978
|
-
/** Lists safe key DTOs.
|
|
3979
|
-
* @param accessToken - Credential required by the frozen contract.
|
|
3980
|
-
* @returns The parsed key collection.
|
|
3981
|
-
*/
|
|
3982
|
-
async list(accessToken) {
|
|
3983
|
-
this.#authorize(accessToken);
|
|
3984
|
-
return parseCollection(
|
|
3985
|
-
await this.#transport.json({ method: "GET", path: "api-keys" }),
|
|
3682
|
+
};
|
|
3683
|
+
return {
|
|
3684
|
+
create: async (accessToken, input) => parseKeyMaterial(
|
|
3685
|
+
await call(
|
|
3686
|
+
accessToken,
|
|
3687
|
+
(client) => client.POST("/api/v1/api-keys", {
|
|
3688
|
+
body: {
|
|
3689
|
+
...input.allowedModels === void 0 ? {} : { allowed_models: [...input.allowedModels] },
|
|
3690
|
+
budget_currency: "EUR",
|
|
3691
|
+
...input.description === void 0 ? {} : { description: input.description },
|
|
3692
|
+
expires_at: input.expiresAt,
|
|
3693
|
+
...input.maxBudgetAmount === void 0 ? {} : { max_budget_amount: input.maxBudgetAmount },
|
|
3694
|
+
name: input.name,
|
|
3695
|
+
...input.ownerId === null ? {} : { owner_user_id: input.ownerId },
|
|
3696
|
+
owner_type: input.ownerType,
|
|
3697
|
+
...input.projectId === null ? {} : { project_id: input.projectId }
|
|
3698
|
+
}
|
|
3699
|
+
})
|
|
3700
|
+
)
|
|
3701
|
+
),
|
|
3702
|
+
delete: async (accessToken, id) => {
|
|
3703
|
+
await call(
|
|
3704
|
+
accessToken,
|
|
3705
|
+
(client) => client.DELETE("/api/v1/api-keys/{api_key_id}", {
|
|
3706
|
+
params: { path: { api_key_id: id } }
|
|
3707
|
+
})
|
|
3708
|
+
);
|
|
3709
|
+
},
|
|
3710
|
+
get: async (accessToken, id) => parseApiKey(
|
|
3711
|
+
await call(
|
|
3712
|
+
accessToken,
|
|
3713
|
+
(client) => client.GET("/api/v1/api-keys/{api_key_id}", {
|
|
3714
|
+
params: { path: { api_key_id: id } }
|
|
3715
|
+
})
|
|
3716
|
+
)
|
|
3717
|
+
),
|
|
3718
|
+
list: async (accessToken) => parseCollection(
|
|
3719
|
+
await call(accessToken, (client) => client.GET("/api/v1/api-keys", {})),
|
|
3986
3720
|
parseApiKey
|
|
3987
|
-
)
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
* @param accessToken - Credential required by the frozen contract.
|
|
3991
|
-
* @returns The parsed organization collection.
|
|
3992
|
-
*/
|
|
3993
|
-
async listOrganizations(accessToken) {
|
|
3994
|
-
this.#authorize(accessToken);
|
|
3995
|
-
return parseCollection(
|
|
3996
|
-
await this.#transport.json({ method: "GET", path: "orgs" }),
|
|
3721
|
+
),
|
|
3722
|
+
listOrganizations: async (accessToken) => parseCollection(
|
|
3723
|
+
await call(accessToken, (client) => client.GET("/api/v1/orgs", {})),
|
|
3997
3724
|
parseOrganization
|
|
3998
|
-
)
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
)
|
|
4058
|
-
}
|
|
4059
|
-
#authorize(accessToken) {
|
|
4060
|
-
if (accessToken.value !== this.#credential.value) {
|
|
4061
|
-
throw new ManagementError("MANAGEMENT_UNAUTHORIZED", {
|
|
4062
|
-
statusCode: 401
|
|
4063
|
-
});
|
|
4064
|
-
}
|
|
4065
|
-
}
|
|
4066
|
-
};
|
|
4067
|
-
|
|
4068
|
-
// src/lazy-management-keys/lazy-management-keys.ts
|
|
4069
|
-
var lazyManagementKeys = (options) => {
|
|
4070
|
-
const client = (accessToken) => new HttpManagementKeys({
|
|
4071
|
-
baseUrl: options.apiBaseUrl,
|
|
4072
|
-
credential: accessToken,
|
|
4073
|
-
...options.fetchImpl === void 0 ? {} : { fetchImpl: options.fetchImpl }
|
|
4074
|
-
});
|
|
4075
|
-
return {
|
|
4076
|
-
create: async (accessToken, input) => client(accessToken).create(accessToken, input),
|
|
4077
|
-
delete: async (accessToken, id) => client(accessToken).delete(accessToken, id),
|
|
4078
|
-
get: async (accessToken, id) => client(accessToken).get(accessToken, id),
|
|
4079
|
-
list: async (accessToken) => client(accessToken).list(accessToken),
|
|
4080
|
-
listOrganizations: async (accessToken) => client(accessToken).listOrganizations(accessToken),
|
|
4081
|
-
listProjects: async (accessToken, organisationId) => client(accessToken).listProjects(accessToken, organisationId),
|
|
4082
|
-
regenerate: async (accessToken, id, expiresAt) => client(accessToken).regenerate(accessToken, id, expiresAt),
|
|
4083
|
-
update: async (accessToken, id, input) => client(accessToken).update(accessToken, id, input)
|
|
3725
|
+
),
|
|
3726
|
+
listMemberships: async (accessToken, userId) => parseUserMemberships(
|
|
3727
|
+
await call(
|
|
3728
|
+
accessToken,
|
|
3729
|
+
(client) => client.GET("/api/v1/users/{user_id}/memberships", {
|
|
3730
|
+
params: { path: { user_id: userId } }
|
|
3731
|
+
})
|
|
3732
|
+
)
|
|
3733
|
+
),
|
|
3734
|
+
listProjectBudgets: async (accessToken, userId) => parseCollection(
|
|
3735
|
+
await call(
|
|
3736
|
+
accessToken,
|
|
3737
|
+
(client) => client.GET("/api/v1/users/{user_id}/project-budgets", {
|
|
3738
|
+
params: { path: { user_id: userId } }
|
|
3739
|
+
})
|
|
3740
|
+
),
|
|
3741
|
+
parseProjectBudgetState
|
|
3742
|
+
),
|
|
3743
|
+
listProjects: async (accessToken, organisationId) => {
|
|
3744
|
+
if (organisationId.trim().length === 0) {
|
|
3745
|
+
throw new ManagementError("MANAGEMENT_ORGANISATION_ID_REQUIRED", {
|
|
3746
|
+
statusCode: 400
|
|
3747
|
+
});
|
|
3748
|
+
}
|
|
3749
|
+
const query = {
|
|
3750
|
+
member_user_id: parseManagementSubject(accessToken),
|
|
3751
|
+
org_id: organisationId
|
|
3752
|
+
};
|
|
3753
|
+
const fetchPage = (cursor) => call(
|
|
3754
|
+
accessToken,
|
|
3755
|
+
(client) => client.GET("/api/v1/projects", {
|
|
3756
|
+
params: {
|
|
3757
|
+
query: cursor === "" ? query : { ...query, cursor }
|
|
3758
|
+
}
|
|
3759
|
+
})
|
|
3760
|
+
).then((page) => parseCollection(page, parseProject));
|
|
3761
|
+
return drainPages(fetchPage);
|
|
3762
|
+
},
|
|
3763
|
+
regenerate: async (accessToken, id, expiresAt) => parseKeyMaterial(
|
|
3764
|
+
await call(
|
|
3765
|
+
accessToken,
|
|
3766
|
+
(client) => client.POST("/api/v1/api-keys/{api_key_id}/secrets", {
|
|
3767
|
+
body: expiresAt === void 0 ? {} : { expires_at: expiresAt },
|
|
3768
|
+
params: { path: { api_key_id: id } }
|
|
3769
|
+
})
|
|
3770
|
+
)
|
|
3771
|
+
),
|
|
3772
|
+
update: async (accessToken, id, input) => parseApiKey(
|
|
3773
|
+
await call(
|
|
3774
|
+
accessToken,
|
|
3775
|
+
(client) => client.PATCH("/api/v1/api-keys/{api_key_id}", {
|
|
3776
|
+
body: {
|
|
3777
|
+
budget_currency: "EUR",
|
|
3778
|
+
...input.expiresAt === void 0 ? {} : { expires_at: input.expiresAt },
|
|
3779
|
+
...input.name === void 0 ? {} : { name: input.name }
|
|
3780
|
+
},
|
|
3781
|
+
params: { path: { api_key_id: id } }
|
|
3782
|
+
})
|
|
3783
|
+
)
|
|
3784
|
+
)
|
|
4084
3785
|
};
|
|
4085
3786
|
};
|
|
4086
3787
|
|
|
@@ -4096,7 +3797,7 @@ var buildProductionRuntimeOptions = (input) => ({
|
|
|
4096
3797
|
timeoutMs: LOGIN_BUDGET_MS
|
|
4097
3798
|
},
|
|
4098
3799
|
management: {
|
|
4099
|
-
client: () =>
|
|
3800
|
+
client: () => sdkManagementKeys({ apiBaseUrl: input.apiBaseUrl })
|
|
4100
3801
|
},
|
|
4101
3802
|
...input.tokenStore === void 0 ? {} : { tokenStore: input.tokenStore }
|
|
4102
3803
|
});
|
|
@@ -4120,97 +3821,10 @@ var createHostAuthBridge = () => {
|
|
|
4120
3821
|
};
|
|
4121
3822
|
};
|
|
4122
3823
|
|
|
4123
|
-
// src/auth/authorization-url-stash/loopback-origin/loopback-origin.ts
|
|
4124
|
-
var loopbackOrigin = (url) => {
|
|
4125
|
-
const redirect = url.searchParams.get("redirect_uri");
|
|
4126
|
-
if (redirect === null) return void 0;
|
|
4127
|
-
let parsed;
|
|
4128
|
-
try {
|
|
4129
|
-
parsed = new URL(redirect);
|
|
4130
|
-
} catch {
|
|
4131
|
-
return void 0;
|
|
4132
|
-
}
|
|
4133
|
-
return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" ? parsed.origin : void 0;
|
|
4134
|
-
};
|
|
4135
|
-
|
|
4136
|
-
// src/auth/authorization-url-stash/authorization-url-stash.ts
|
|
4137
|
-
var FALLBACK_URL = "https://route33.ai";
|
|
4138
|
-
var SIGN_IN_INSTRUCTIONS = "Open the Route 33 sign-in link \u2014 your browser will finish at a confirmation page.";
|
|
4139
|
-
var FINISHING_INSTRUCTIONS = "Finishing Route 33 setup\u2026";
|
|
4140
|
-
var URL_WAIT_BUDGET_MS = 3e4;
|
|
4141
|
-
var LISTENER_PROBE_TIMEOUT_MS = 750;
|
|
4142
|
-
var createAuthorizationUrlStash = (options = {}) => {
|
|
4143
|
-
let latest;
|
|
4144
|
-
let waiters = [];
|
|
4145
|
-
const browserRunner = (url) => {
|
|
4146
|
-
latest = url;
|
|
4147
|
-
const publish = waiters;
|
|
4148
|
-
waiters = [];
|
|
4149
|
-
for (const resolve2 of publish) resolve2(url);
|
|
4150
|
-
return Promise.resolve();
|
|
4151
|
-
};
|
|
4152
|
-
const usableCandidate = async (url) => {
|
|
4153
|
-
const origin = loopbackOrigin(url);
|
|
4154
|
-
if (origin === void 0) return url;
|
|
4155
|
-
const controller = new AbortController();
|
|
4156
|
-
const timer = setTimeout(() => {
|
|
4157
|
-
controller.abort();
|
|
4158
|
-
}, options.listenerProbeTimeoutMs ?? LISTENER_PROBE_TIMEOUT_MS);
|
|
4159
|
-
try {
|
|
4160
|
-
const response = await (options.fetchImpl ?? fetch)(`${origin}/`, {
|
|
4161
|
-
signal: controller.signal
|
|
4162
|
-
});
|
|
4163
|
-
return response.status >= 200 ? url : void 0;
|
|
4164
|
-
} catch {
|
|
4165
|
-
return void 0;
|
|
4166
|
-
} finally {
|
|
4167
|
-
clearTimeout(timer);
|
|
4168
|
-
}
|
|
4169
|
-
};
|
|
4170
|
-
const urlForConnect = async (callback) => {
|
|
4171
|
-
let decide;
|
|
4172
|
-
const decided = new Promise((resolve2) => {
|
|
4173
|
-
decide = resolve2;
|
|
4174
|
-
});
|
|
4175
|
-
const settle = (decision) => {
|
|
4176
|
-
clearTimeout(timer);
|
|
4177
|
-
decide(decision);
|
|
4178
|
-
};
|
|
4179
|
-
const timer = setTimeout(() => {
|
|
4180
|
-
settle({ instructions: SIGN_IN_INSTRUCTIONS, url: FALLBACK_URL });
|
|
4181
|
-
}, options.urlWaitBudgetMs ?? URL_WAIT_BUDGET_MS);
|
|
4182
|
-
void Promise.resolve(callback).catch(() => void 0).then(() => {
|
|
4183
|
-
settle({ instructions: FINISHING_INSTRUCTIONS, url: FALLBACK_URL });
|
|
4184
|
-
});
|
|
4185
|
-
const serve = (url) => {
|
|
4186
|
-
settle({ instructions: SIGN_IN_INSTRUCTIONS, url: url.toString() });
|
|
4187
|
-
};
|
|
4188
|
-
const awaitPublish = () => {
|
|
4189
|
-
const publish = new Promise((resolve2) => {
|
|
4190
|
-
waiters.push(resolve2);
|
|
4191
|
-
});
|
|
4192
|
-
void publish.then(serve);
|
|
4193
|
-
};
|
|
4194
|
-
const candidate = latest;
|
|
4195
|
-
if (candidate === void 0) {
|
|
4196
|
-
awaitPublish();
|
|
4197
|
-
} else {
|
|
4198
|
-
void usableCandidate(candidate).then((usable) => {
|
|
4199
|
-
if (usable !== void 0) {
|
|
4200
|
-
serve(usable);
|
|
4201
|
-
} else if (latest !== void 0 && latest !== candidate) {
|
|
4202
|
-
serve(latest);
|
|
4203
|
-
} else {
|
|
4204
|
-
awaitPublish();
|
|
4205
|
-
}
|
|
4206
|
-
});
|
|
4207
|
-
}
|
|
4208
|
-
return decided;
|
|
4209
|
-
};
|
|
4210
|
-
return { browserRunner, urlForConnect };
|
|
4211
|
-
};
|
|
4212
|
-
|
|
4213
3824
|
// src/v1-entry/route33-auth-hook/route33-auth-hook.ts
|
|
3825
|
+
import {
|
|
3826
|
+
createAuthorizationUrlStash
|
|
3827
|
+
} from "@r-33/auth-browser";
|
|
4214
3828
|
var createRoute33AuthHook = (deps) => ({
|
|
4215
3829
|
loader: async (auth) => {
|
|
4216
3830
|
deps.bridge.hydrate(await auth());
|
|
@@ -4410,6 +4024,7 @@ var contractFixtures = {
|
|
|
4410
4024
|
var fixtureToWire = (value) => structuredClone(value);
|
|
4411
4025
|
|
|
4412
4026
|
// src/contract/fixtures/parse-contract-fixtures/parse-contract-fixtures.ts
|
|
4027
|
+
import { parseTokenSet } from "@r-33/auth-browser";
|
|
4413
4028
|
var parseContractFixtures = (fixtures) => ({
|
|
4414
4029
|
apiKey: parseApiKey(fixtureToWire(fixtures.apiKey)),
|
|
4415
4030
|
keyMaterial: parseKeyMaterial(fixtureToWire(fixtures.keyMaterial)),
|
|
@@ -4421,10 +4036,10 @@ var parseContractFixtures = (fixtures) => ({
|
|
|
4421
4036
|
var clientId = readEnvClientId() ?? DEFAULT_ROUTE33_CLIENT_ID;
|
|
4422
4037
|
var issuerUrl = readEnvAuthIssuer() ?? DEFAULT_AUTH_ISSUER_URL;
|
|
4423
4038
|
var authBridge = createHostAuthBridge();
|
|
4424
|
-
var startNativeLogin = (browserRunner) =>
|
|
4039
|
+
var startNativeLogin = (browserRunner) => route33Login({
|
|
4425
4040
|
browserRunner,
|
|
4426
4041
|
clientId,
|
|
4427
|
-
session:
|
|
4042
|
+
session: createAuthSession2({ clientId, issuerUrl }),
|
|
4428
4043
|
timeoutMs: LOGIN_BUDGET_MS
|
|
4429
4044
|
});
|
|
4430
4045
|
var route33Plugin = createRoute33Plugin({
|
|
@@ -4478,14 +4093,13 @@ var Route33Plugin = async (input) => {
|
|
|
4478
4093
|
};
|
|
4479
4094
|
export {
|
|
4480
4095
|
AttributionPromptError,
|
|
4481
|
-
|
|
4096
|
+
CALLBACK_PAGE_COPY,
|
|
4482
4097
|
ContractParseError,
|
|
4483
4098
|
DEFAULT_GATEWAY_KEY_RENEWAL_RATIO,
|
|
4484
4099
|
DEFAULT_GATEWAY_KEY_TTL_MS,
|
|
4485
4100
|
FileSecretStore,
|
|
4486
4101
|
GatewayApiKey,
|
|
4487
4102
|
HostStorageSecretStore,
|
|
4488
|
-
HttpManagementKeys,
|
|
4489
4103
|
KeyLeaseError,
|
|
4490
4104
|
LeaseState,
|
|
4491
4105
|
ManagementError,
|
|
@@ -4495,26 +4109,20 @@ export {
|
|
|
4495
4109
|
Route33Plugin,
|
|
4496
4110
|
Route33Runtime,
|
|
4497
4111
|
TRUSTED_PARTY_COPY,
|
|
4498
|
-
buildAuthorizeUrl,
|
|
4499
4112
|
changeAttribution,
|
|
4500
4113
|
clearAttribution,
|
|
4501
4114
|
contractFixtures,
|
|
4502
4115
|
controlOrphans,
|
|
4503
4116
|
createAttributionPrompt,
|
|
4504
|
-
createAuthLoopbackCallback,
|
|
4505
|
-
createAuthSession,
|
|
4506
4117
|
createLeaseInstallationFactory,
|
|
4507
|
-
createPkceVerifierAndChallenge,
|
|
4508
4118
|
createRoute33Plugin,
|
|
4509
4119
|
deriveScopeId,
|
|
4510
4120
|
detectWorktreeRoot,
|
|
4511
|
-
|
|
4121
|
+
drainPages,
|
|
4512
4122
|
fixtureToWire,
|
|
4513
4123
|
inspectSession,
|
|
4514
4124
|
leaseForAttribution,
|
|
4515
|
-
loginFlow,
|
|
4516
4125
|
mintKey,
|
|
4517
|
-
openBrowserAndCapture,
|
|
4518
4126
|
parseApiKey,
|
|
4519
4127
|
parseAttribution,
|
|
4520
4128
|
parseCatalogResult,
|
|
@@ -4526,12 +4134,11 @@ export {
|
|
|
4526
4134
|
parseManagementSubject,
|
|
4527
4135
|
parseOrganization,
|
|
4528
4136
|
parseProject,
|
|
4529
|
-
|
|
4530
|
-
|
|
4137
|
+
parseProjectBudgetState,
|
|
4138
|
+
parseUserMemberships,
|
|
4531
4139
|
readAttribution,
|
|
4532
4140
|
readLegacyKey,
|
|
4533
4141
|
recoverLeaseState,
|
|
4534
|
-
refreshSession,
|
|
4535
4142
|
removeLegacyKey,
|
|
4536
4143
|
renewKey,
|
|
4537
4144
|
resetAttribution,
|
|
@@ -4541,5 +4148,7 @@ export {
|
|
|
4541
4148
|
resolveSeamValue,
|
|
4542
4149
|
reusableLease,
|
|
4543
4150
|
rotateNow,
|
|
4151
|
+
route33Login,
|
|
4152
|
+
sdkManagementKeys,
|
|
4544
4153
|
writeAttribution
|
|
4545
4154
|
};
|