@adelie/server 0.5.7 → 0.5.9

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/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-GO6G445C.js";
9
9
  import {
10
10
  TICKET_SLUG_PATTERN
11
- } from "./chunk-6IXN3YH4.js";
11
+ } from "./chunk-7ROH3XZA.js";
12
12
  import {
13
13
  MachinesRepo
14
14
  } from "./chunk-HMTT2PX4.js";
@@ -25,9 +25,10 @@ import {
25
25
  isMissingCredential,
26
26
  mintApiToken,
27
27
  modelCredentialMissing,
28
+ normalizeError,
28
29
  storeApiToken,
29
30
  toUserInfo
30
- } from "./chunk-CXGWSWJA.js";
31
+ } from "./chunk-3Y7I7J3W.js";
31
32
  import {
32
33
  acquireServerLock,
33
34
  liveServerLock,
@@ -3682,7 +3683,7 @@ import { DEFAULT_PROJECT_ID as DEFAULT_PROJECT_ID3, DEFAULT_PROJECT_NAME as DEFA
3682
3683
 
3683
3684
  // src/ifaces.json
3684
3685
  var ifaces_default = {
3685
- hash: "0b0f68e407b030585d1a39c05a849df1a4d025bd5b85d34c5246b92a42670a96",
3686
+ hash: "82247e20cc9b17bc5831d03e41da41a2e8a8649fb9ea23c6589e2ba3c5713df2",
3686
3687
  ifaces: {
3687
3688
  "@adelie/server#Access": {
3688
3689
  name: "Access",
@@ -23171,7 +23172,10 @@ var ifaces_default = {
23171
23172
  "@adelie/server#ModelOAuthMode": "'callback'|'manual'",
23172
23173
  "@adelie/server#ModelOAuthStartResult": {
23173
23174
  flowId: "string",
23174
- authorizeUrl: "string"
23175
+ authorizeUrl: "string",
23176
+ mode: {
23177
+ $ref: "@adelie/server#ModelOAuthMode"
23178
+ }
23175
23179
  },
23176
23180
  "@adelie/server#ModelOAuthStatus": "'pending'|'done'|'error'",
23177
23181
  "@adelie/server#ModelPricingDto": {
@@ -25250,6 +25254,7 @@ var ifaces_default = {
25250
25254
  "toTs?": "string",
25251
25255
  "until?": "string",
25252
25256
  "agentId?": "string",
25257
+ "kind?": "string",
25253
25258
  "includeGlobalErrors?": "boolean"
25254
25259
  },
25255
25260
  "@adelie/server#UsageErrorsPage": {
@@ -46727,12 +46732,12 @@ var UsageService = class {
46727
46732
  /**
46728
46733
  * Empties the error table for the filter the panel is showing, and answers how many rows went.
46729
46734
  *
46730
- * The filter is the same range (dates, and the trailing window when one is on) and Agent
46731
- * the dashboard and the paged route take, read with the same admin visibility, so a clear
46732
- * removes exactly the set the caller was looking at and never a row outside it: a reader
46733
- * who has narrowed to one Agent and one week does not lose the rest of the year to a button
46734
- * that said "clear", and an admin whose panel showed unattributed rows is not left holding
46735
- * them after clearing it (see ErrorsRepo.deleteFiltered).
46735
+ * The filter is the same range (dates, and the trailing window when one is on), Agent and
46736
+ * category the dashboard and the paged route take, read with the same admin visibility, so a
46737
+ * clear removes exactly the set the caller was looking at and never a row outside it: a
46738
+ * reader who has narrowed to one Agent, one week or one category does not lose the rest to a
46739
+ * button that said "clear", and an admin whose panel showed unattributed rows is not left
46740
+ * holding them after clearing it (see ErrorsRepo.deleteFiltered).
46736
46741
  */
46737
46742
  clearErrors(projectId, q) {
46738
46743
  return this.errors.deleteFiltered(projectId, {
@@ -46742,6 +46747,7 @@ var UsageService = class {
46742
46747
  ...q.fromTs !== void 0 ? { fromTs: q.fromTs } : {},
46743
46748
  ...q.toTs !== void 0 ? { toTs: q.toTs } : {},
46744
46749
  ...q.until !== void 0 ? { until: q.until } : {},
46750
+ ...q.kind !== void 0 ? { kind: q.kind } : {},
46745
46751
  ...q.includeGlobalErrors === true ? { includeGlobal: true } : {}
46746
46752
  });
46747
46753
  }
@@ -47860,6 +47866,18 @@ import { APP_URL, providerInfo as providerInfo2 } from "@adelie/core/model-catal
47860
47866
  import { Component as Component35, Use as Use35 } from "@adelie/core/kernel";
47861
47867
  var FLOW_TTL_MS = 10 * 60 * 1e3;
47862
47868
  var MAX_FLOWS_PER_OWNER = 8;
47869
+ function openedMode(asked, callbackOrigin) {
47870
+ if (asked === "manual") return "manual";
47871
+ let origin;
47872
+ try {
47873
+ origin = new URL(callbackOrigin);
47874
+ } catch {
47875
+ return "manual";
47876
+ }
47877
+ if (origin.protocol === "https:") return "callback";
47878
+ const loopback = origin.hostname === "localhost" || origin.hostname === "[::1]" || /^127(?:\.\d{1,3}){3}$/.test(origin.hostname);
47879
+ return origin.protocol === "http:" && loopback ? "callback" : "manual";
47880
+ }
47863
47881
  function createVerifier() {
47864
47882
  return `${randomUUID6()}${randomUUID6()}`;
47865
47883
  }
@@ -47923,6 +47941,9 @@ var ModelOAuthService = class {
47923
47941
  * that declares no `oauth` cannot be talked into one, and the authorize/exchange
47924
47942
  * endpoints are always the catalog's, so client input never chooses who receives the
47925
47943
  * challenge or who is asked for a key.
47944
+ *
47945
+ * A redirect that the authorization page would refuse is not asked for: the flow opens in
47946
+ * manual mode instead (see {@link openedMode}) and the result says so.
47926
47947
  */
47927
47948
  start(input) {
47928
47949
  const oauth = providerInfo2(input.provider)?.oauth;
@@ -47934,13 +47955,14 @@ var ModelOAuthService = class {
47934
47955
  const flowId3 = randomBytes7(32).toString("base64url");
47935
47956
  const verifier = createVerifier();
47936
47957
  const createdAt = this.now();
47937
- const callbackUrl = input.mode === "callback" ? `${input.callbackOrigin}/api/projects/${encodeURIComponent(input.projectId)}/model-oauth/callback?flow=${encodeURIComponent(flowId3)}` : void 0;
47958
+ const mode = openedMode(input.mode, input.callbackOrigin);
47959
+ const callbackUrl = mode === "callback" ? `${input.callbackOrigin}/api/projects/${encodeURIComponent(input.projectId)}/model-oauth/callback?flow=${encodeURIComponent(flowId3)}` : void 0;
47938
47960
  this.flows.set(flowId3, {
47939
47961
  flowId: flowId3,
47940
47962
  projectId: input.projectId,
47941
47963
  userId: input.userId,
47942
47964
  provider: input.provider,
47943
- mode: input.mode,
47965
+ mode,
47944
47966
  exchangeUrl: oauth.exchangeUrl,
47945
47967
  verifier,
47946
47968
  code: null,
@@ -47954,7 +47976,8 @@ var ModelOAuthService = class {
47954
47976
  oauth,
47955
47977
  challenge: codeChallenge(verifier),
47956
47978
  ...callbackUrl !== void 0 ? { callbackUrl } : {}
47957
- })
47979
+ }),
47980
+ mode
47958
47981
  };
47959
47982
  }
47960
47983
  /**
@@ -55960,13 +55983,18 @@ function usageRoutes(deps) {
55960
55983
  const window = tsWindowQuery(c);
55961
55984
  const until = optionalTsParam(c.req.query("until"), "until");
55962
55985
  const agentId = c.req.query("agentId");
55986
+ const kindRaw = c.req.query("kind");
55987
+ if (kindRaw !== void 0 && kindRaw !== "" && !ERROR_KINDS.includes(kindRaw)) {
55988
+ throw badRequest(`kind must be one of ${ERROR_KINDS.join(" / ")}.`);
55989
+ }
55963
55990
  const deleted = deps.usageService.clearErrors(projectId, {
55964
55991
  includeGlobalErrors: c.var.user.isAdmin,
55965
55992
  from,
55966
55993
  to,
55967
55994
  ...window,
55968
55995
  ...until !== void 0 ? { until } : {},
55969
- ...agentId !== void 0 && agentId !== "" ? { agentId } : {}
55996
+ ...agentId !== void 0 && agentId !== "" ? { agentId } : {},
55997
+ ...kindRaw !== void 0 && kindRaw !== "" ? { kind: kindRaw } : {}
55970
55998
  });
55971
55999
  return c.json({ deleted });
55972
56000
  });
@@ -75235,12 +75263,13 @@ var HttpModule = class {
75235
75263
  const app = new Hono49();
75236
75264
  app.onError((err, c) => {
75237
75265
  const projectId = attributedProjectId(c, { access });
75266
+ const normalized = normalizeError(err);
75238
75267
  errors.record({
75239
75268
  source: "http",
75240
- err,
75269
+ err: normalized,
75241
75270
  ...projectId !== void 0 ? { ctx: { projectId } } : {}
75242
75271
  });
75243
- return handleError(err, c);
75272
+ return handleError(normalized, c);
75244
75273
  });
75245
75274
  app.notFound(() => declined());
75246
75275
  app.use("*", async (c, next) => {
@@ -81553,12 +81582,13 @@ function createApp(boot3) {
81553
81582
  const app = new Hono55();
81554
81583
  app.onError((err, c) => {
81555
81584
  const projectId = attributedProjectId(c, { access: access() });
81585
+ const normalized = normalizeError(err);
81556
81586
  errors().record({
81557
81587
  source: "http",
81558
- err,
81588
+ err: normalized,
81559
81589
  ...projectId !== void 0 ? { ctx: { projectId } } : {}
81560
81590
  });
81561
- return handleError(err, c);
81591
+ return handleError(normalized, c);
81562
81592
  });
81563
81593
  app.notFound((c) => c.json(errorBody("not_found", "Endpoint does not exist."), 404));
81564
81594
  app.use("*", async (c, next) => {