@adelie/server 0.5.8 → 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";
@@ -3683,7 +3683,7 @@ import { DEFAULT_PROJECT_ID as DEFAULT_PROJECT_ID3, DEFAULT_PROJECT_NAME as DEFA
3683
3683
 
3684
3684
  // src/ifaces.json
3685
3685
  var ifaces_default = {
3686
- hash: "0b0f68e407b030585d1a39c05a849df1a4d025bd5b85d34c5246b92a42670a96",
3686
+ hash: "82247e20cc9b17bc5831d03e41da41a2e8a8649fb9ea23c6589e2ba3c5713df2",
3687
3687
  ifaces: {
3688
3688
  "@adelie/server#Access": {
3689
3689
  name: "Access",
@@ -23172,7 +23172,10 @@ var ifaces_default = {
23172
23172
  "@adelie/server#ModelOAuthMode": "'callback'|'manual'",
23173
23173
  "@adelie/server#ModelOAuthStartResult": {
23174
23174
  flowId: "string",
23175
- authorizeUrl: "string"
23175
+ authorizeUrl: "string",
23176
+ mode: {
23177
+ $ref: "@adelie/server#ModelOAuthMode"
23178
+ }
23176
23179
  },
23177
23180
  "@adelie/server#ModelOAuthStatus": "'pending'|'done'|'error'",
23178
23181
  "@adelie/server#ModelPricingDto": {
@@ -25251,6 +25254,7 @@ var ifaces_default = {
25251
25254
  "toTs?": "string",
25252
25255
  "until?": "string",
25253
25256
  "agentId?": "string",
25257
+ "kind?": "string",
25254
25258
  "includeGlobalErrors?": "boolean"
25255
25259
  },
25256
25260
  "@adelie/server#UsageErrorsPage": {
@@ -46728,12 +46732,12 @@ var UsageService = class {
46728
46732
  /**
46729
46733
  * Empties the error table for the filter the panel is showing, and answers how many rows went.
46730
46734
  *
46731
- * The filter is the same range (dates, and the trailing window when one is on) and Agent
46732
- * the dashboard and the paged route take, read with the same admin visibility, so a clear
46733
- * removes exactly the set the caller was looking at and never a row outside it: a reader
46734
- * who has narrowed to one Agent and one week does not lose the rest of the year to a button
46735
- * that said "clear", and an admin whose panel showed unattributed rows is not left holding
46736
- * 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).
46737
46741
  */
46738
46742
  clearErrors(projectId, q) {
46739
46743
  return this.errors.deleteFiltered(projectId, {
@@ -46743,6 +46747,7 @@ var UsageService = class {
46743
46747
  ...q.fromTs !== void 0 ? { fromTs: q.fromTs } : {},
46744
46748
  ...q.toTs !== void 0 ? { toTs: q.toTs } : {},
46745
46749
  ...q.until !== void 0 ? { until: q.until } : {},
46750
+ ...q.kind !== void 0 ? { kind: q.kind } : {},
46746
46751
  ...q.includeGlobalErrors === true ? { includeGlobal: true } : {}
46747
46752
  });
46748
46753
  }
@@ -47861,6 +47866,18 @@ import { APP_URL, providerInfo as providerInfo2 } from "@adelie/core/model-catal
47861
47866
  import { Component as Component35, Use as Use35 } from "@adelie/core/kernel";
47862
47867
  var FLOW_TTL_MS = 10 * 60 * 1e3;
47863
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
+ }
47864
47881
  function createVerifier() {
47865
47882
  return `${randomUUID6()}${randomUUID6()}`;
47866
47883
  }
@@ -47924,6 +47941,9 @@ var ModelOAuthService = class {
47924
47941
  * that declares no `oauth` cannot be talked into one, and the authorize/exchange
47925
47942
  * endpoints are always the catalog's, so client input never chooses who receives the
47926
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.
47927
47947
  */
47928
47948
  start(input) {
47929
47949
  const oauth = providerInfo2(input.provider)?.oauth;
@@ -47935,13 +47955,14 @@ var ModelOAuthService = class {
47935
47955
  const flowId3 = randomBytes7(32).toString("base64url");
47936
47956
  const verifier = createVerifier();
47937
47957
  const createdAt = this.now();
47938
- 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;
47939
47960
  this.flows.set(flowId3, {
47940
47961
  flowId: flowId3,
47941
47962
  projectId: input.projectId,
47942
47963
  userId: input.userId,
47943
47964
  provider: input.provider,
47944
- mode: input.mode,
47965
+ mode,
47945
47966
  exchangeUrl: oauth.exchangeUrl,
47946
47967
  verifier,
47947
47968
  code: null,
@@ -47955,7 +47976,8 @@ var ModelOAuthService = class {
47955
47976
  oauth,
47956
47977
  challenge: codeChallenge(verifier),
47957
47978
  ...callbackUrl !== void 0 ? { callbackUrl } : {}
47958
- })
47979
+ }),
47980
+ mode
47959
47981
  };
47960
47982
  }
47961
47983
  /**
@@ -55961,13 +55983,18 @@ function usageRoutes(deps) {
55961
55983
  const window = tsWindowQuery(c);
55962
55984
  const until = optionalTsParam(c.req.query("until"), "until");
55963
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
+ }
55964
55990
  const deleted = deps.usageService.clearErrors(projectId, {
55965
55991
  includeGlobalErrors: c.var.user.isAdmin,
55966
55992
  from,
55967
55993
  to,
55968
55994
  ...window,
55969
55995
  ...until !== void 0 ? { until } : {},
55970
- ...agentId !== void 0 && agentId !== "" ? { agentId } : {}
55996
+ ...agentId !== void 0 && agentId !== "" ? { agentId } : {},
55997
+ ...kindRaw !== void 0 && kindRaw !== "" ? { kind: kindRaw } : {}
55971
55998
  });
55972
55999
  return c.json({ deleted });
55973
56000
  });