@unisonlabs/sixminute-admin 0.1.1391-next → 0.1.1392-next

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.
@@ -20,7 +20,7 @@ import { homedir } from "node:os";
20
20
  import { fileURLToPath } from "node:url";
21
21
 
22
22
  // tools/admin/src/build-info.ts
23
- var BUILT = { version: "0.1.1391-next", commit: "39fc32132e0748ee887937a4f6aafb7d4df9d823", surface: "fd82872ec0f64638" };
23
+ var BUILT = { version: "0.1.1392-next", commit: "52ec367697fe4cff6749f5809f0534e6ba9645e5", surface: "ac6c731b1016a56b" };
24
24
 
25
25
  // tools/admin/src/run.ts
26
26
  import { readFileSync as readFileSync4, writeFileSync as writeFileSync2 } from "node:fs";
@@ -6826,6 +6826,7 @@ var AdminLearningReportSchema = exports_external.object({
6826
6826
  });
6827
6827
  // packages/contracts/src/admin-firm-acting.ts
6828
6828
  var ACTING_AS_HEADER = "X-Six-Minute-Acting-As";
6829
+ var ACTING_FOR_HEADER = "X-Six-Minute-Acting-For";
6829
6830
  var TeamApplyRequestSchema = exports_external.object({
6830
6831
  bind: exports_external.array(exports_external.object({ external_ref: exports_external.string().min(1), member_id: MemberIdSchema })).default([]),
6831
6832
  unbind: exports_external.array(exports_external.string().min(1)).default([]),
@@ -8778,11 +8779,12 @@ function outdatedMessage(environment) {
8778
8779
  return `this sixminute-admin does not match the ${environment.name} API's operator routes. Update it:
8779
8780
  ` + ` ${installLineFor(environment.name, ADMIN_INSTALL_LINE)}`;
8780
8781
  }
8781
- async function send(ctx, token, method, path, body) {
8782
+ async function send(ctx, token, method, path, body, actingFor) {
8782
8783
  const headers = {
8783
8784
  Authorization: `Bearer ${token}`,
8784
8785
  [ADMIN_SURFACE_HEADER]: ctx.surface,
8785
- Accept: "application/json"
8786
+ Accept: "application/json",
8787
+ ...actingFor === undefined ? {} : { [ACTING_FOR_HEADER]: actingFor }
8786
8788
  };
8787
8789
  if (body !== undefined)
8788
8790
  headers["Content-Type"] = "application/json";
@@ -8802,12 +8804,12 @@ async function send(ctx, token, method, path, body) {
8802
8804
  }
8803
8805
  return { status: response.status, body: parsed, actingAs: response.headers.get(ACTING_AS_HEADER) };
8804
8806
  }
8805
- async function call(ctx, method, path, body) {
8807
+ async function call(ctx, method, path, body, actingFor) {
8806
8808
  let session = await currentSession(ctx.io, ctx.environment);
8807
- let answer = await send(ctx, session.access_token, method, path, body);
8809
+ let answer = await send(ctx, session.access_token, method, path, body, actingFor);
8808
8810
  if (answer.status === 401) {
8809
8811
  session = await refreshSession(ctx.io, ctx.environment, session);
8810
- answer = await send(ctx, session.access_token, method, path, body);
8812
+ answer = await send(ctx, session.access_token, method, path, body, actingFor);
8811
8813
  if (answer.status === 401) {
8812
8814
  throw new AdminUsageError(`the ${ctx.environment.name} API refused the sign-in; ${signInAgain(ctx.environment.name)}`);
8813
8815
  }
@@ -9171,7 +9173,7 @@ async function runMember(run2, subcommand) {
9171
9173
  const { flags } = run2;
9172
9174
  const tenant = required(flags, "tenant", "whose members");
9173
9175
  if (subcommand === "list") {
9174
- const answer = await call(run2.api, "GET", tenantPath(tenant, "/members"));
9176
+ const answer = await firmCall(run2, tenant, "GET", "/v1/members");
9175
9177
  const { members, invitations } = MembersSchema.parse(expectOk(answer));
9176
9178
  return render(run2, { members, invitations }, [
9177
9179
  actingHead(tenant, answer),
@@ -9190,7 +9192,7 @@ async function runMember(run2, subcommand) {
9190
9192
  if (role === undefined && active === undefined) {
9191
9193
  throw new AdminUsageError("name what changes: --role admin|billing|timekeeper, --active true|false, or both");
9192
9194
  }
9193
- const answer = await call(run2.api, "PATCH", tenantPath(tenant, `/members/${enc(member)}`), {
9195
+ const answer = await firmCall(run2, tenant, "PATCH", `/v1/members/${enc(member)}`, {
9194
9196
  ...role === undefined ? {} : { role },
9195
9197
  ...active === undefined ? {} : { active }
9196
9198
  });
@@ -9202,14 +9204,14 @@ async function runMember(run2, subcommand) {
9202
9204
  }
9203
9205
  if (subcommand === "internal") {
9204
9206
  const member = required(flags, "member", "whose own internal matters (member list prints the member_... ids)");
9205
- const path = tenantPath(tenant, `/members/${enc(member)}/internal-matters`);
9207
+ const path = `/v1/members/${enc(member)}/internal-matters`;
9206
9208
  const matter = optional(flags, "matter");
9207
9209
  const [on, off] = [switched(flags, "on"), switched(flags, "off")];
9208
9210
  if (matter === undefined && (on || off))
9209
9211
  throw new AdminUsageError("--on and --off need --matter: which matter_... to put on the list or take off");
9210
9212
  if (matter !== undefined && on === off)
9211
9213
  throw new AdminUsageError("say --on or --off: put the matter on the member's own internal matters, or take it off");
9212
- const answer = matter === undefined ? await call(run2.api, "GET", path) : await call(run2.api, "PUT", `${path}/${enc(matter)}`, { internal: on });
9214
+ const answer = matter === undefined ? await firmCall(run2, tenant, "GET", path) : await firmCall(run2, tenant, "PUT", `${path}/${enc(matter)}`, { internal: on });
9213
9215
  if (answer.status !== 200)
9214
9216
  return refused(run2, answer, [actingHead(tenant, answer)]);
9215
9217
  const { matter_ids } = PersonalInternalSchema.parse(answer.body);
@@ -10015,6 +10017,7 @@ async function runFirm(run2, group, subcommand) {
10015
10017
  ${ADMIN_USAGE}`);
10016
10018
  }
10017
10019
  var tenantPath = (tenant, rest = "") => `/v1/admin/tenants/${enc2(tenant)}${rest}`;
10020
+ var firmCall = (run2, tenant, method, path, body) => call(run2.api, method, path, body, tenant);
10018
10021
  async function runTenantList(run2) {
10019
10022
  const { tenants } = AdminTenantListSchema.parse(expectOk(await call(run2.api, "GET", "/v1/admin/tenants")));
10020
10023
  return render(run2, { tenants }, tenants.length === 0 ? ["no firms"] : tenants.map((t) => `${t.id} ${t.workos_org_id} ${t.security_tier.padEnd(12)} ${t.internal ? "internal " : " "}${t.name}`));
@@ -10233,12 +10236,11 @@ async function runAudit(run2) {
10233
10236
  async function runVocabulary(run2, group, subcommand, action, positionals) {
10234
10237
  const { flags } = run2;
10235
10238
  const tenant = required(flags, "tenant", "the firm whose vocabulary this is");
10236
- const base = tenantPath(tenant);
10237
10239
  let head = null;
10238
10240
  const firm2 = async (method, path, body) => {
10239
- const answer = await call(run2.api, method, `${base}${path}`, body);
10241
+ const answer = await firmCall(run2, tenant, method, `/v1${path}`, body);
10240
10242
  head ??= actingHead(tenant, answer);
10241
- return expectOk(answer, `${method} ${base}${path}`);
10243
+ return expectOk(answer, `${method} /v1${path}`);
10242
10244
  };
10243
10245
  const done = (payload, lines) => render(run2, payload, [...head === null ? [] : [head], ...lines]);
10244
10246
  const attributes = async () => exports_external.array(AttributeSchema).parse(await firm2("GET", "/attributes"));
@@ -10360,7 +10362,7 @@ async function pullAll(run2, tenant, path, row) {
10360
10362
  let head = null;
10361
10363
  for (;; ) {
10362
10364
  const query = since === null ? `?limit=${PULL_PAGE}` : `?limit=${PULL_PAGE}&since=${enc2(since)}`;
10363
- const answer = await call(run2.api, "GET", tenantPath(tenant, `${path}${query}`));
10365
+ const answer = await firmCall(run2, tenant, "GET", `/v1${path}${query}`);
10364
10366
  head ??= actingHead(tenant, answer);
10365
10367
  const page = pullResultSchema(row).parse(expectOk(answer));
10366
10368
  rows.push(...page.rows);
@@ -10391,7 +10393,7 @@ async function runClient(run2, subcommand) {
10391
10393
  external_ref: optional(flags, "external-ref")
10392
10394
  });
10393
10395
  checkBody(ClientInputSchema, body);
10394
- const answer = await call(run2.api, "POST", tenantPath(tenant, "/clients"), body);
10396
+ const answer = await firmCall(run2, tenant, "POST", "/v1/clients", body);
10395
10397
  if (answer.status !== 201)
10396
10398
  return refused(run2, answer, [actingHead(tenant, answer)]);
10397
10399
  const client2 = ClientSchema.parse(answer.body);
@@ -10421,7 +10423,7 @@ async function runClient(run2, subcommand) {
10421
10423
  `));
10422
10424
  }
10423
10425
  }
10424
- const answer = await call(run2.api, "PATCH", tenantPath(tenant, `/clients/${enc2(id)}`), body);
10426
+ const answer = await firmCall(run2, tenant, "PATCH", `/v1/clients/${enc2(id)}`, body);
10425
10427
  if (answer.status !== 200)
10426
10428
  return refused(run2, answer, [actingHead(tenant, answer)]);
10427
10429
  const client2 = ClientSchema.parse(answer.body);
@@ -10448,7 +10450,7 @@ async function runMatter(run2, subcommand) {
10448
10450
  temporary: booleanOf(flags, "temporary")
10449
10451
  });
10450
10452
  checkBody(MatterInputSchema, body);
10451
- const answer = await call(run2.api, "POST", tenantPath(tenant, "/matters"), body);
10453
+ const answer = await firmCall(run2, tenant, "POST", "/v1/matters", body);
10452
10454
  if (answer.status !== 201)
10453
10455
  return refused(run2, answer, [actingHead(tenant, answer)]);
10454
10456
  const matter = MatterSchema.parse(answer.body);
@@ -10483,7 +10485,7 @@ async function runMatter(run2, subcommand) {
10483
10485
  external_ref: optional(flags, "external-ref"),
10484
10486
  active: booleanOf(flags, "active")
10485
10487
  }, MatterPatchSchema, "--name, --number, --description, --external-ref, --active") : { active: subcommand === "unarchive" };
10486
- const answer = await call(run2.api, "PATCH", tenantPath(tenant, `/matters/${enc2(id)}`), body);
10488
+ const answer = await firmCall(run2, tenant, "PATCH", `/v1/matters/${enc2(id)}`, body);
10487
10489
  if (answer.status !== 200)
10488
10490
  return refused(run2, answer, [actingHead(tenant, answer)]);
10489
10491
  const matter = MatterSchema.parse(answer.body);
@@ -10494,7 +10496,7 @@ async function runMatter(run2, subcommand) {
10494
10496
  const [on, off] = [switched(flags, "on"), switched(flags, "off")];
10495
10497
  if (on === off)
10496
10498
  throw new AdminUsageError("say --on or --off: mark the matter as the firm's own, or clear the mark");
10497
- const answer = await call(run2.api, "PUT", tenantPath(tenant, `/matters/${enc2(id)}/firm-internal`), { firm_internal: on });
10499
+ const answer = await firmCall(run2, tenant, "PUT", `/v1/matters/${enc2(id)}/firm-internal`, { firm_internal: on });
10498
10500
  if (answer.status !== 200)
10499
10501
  return refused(run2, answer, [actingHead(tenant, answer)]);
10500
10502
  const matter = MatterSchema.parse(answer.body);
@@ -10507,7 +10509,7 @@ async function runMattersImport(run2) {
10507
10509
  const tenant = required(flags, "tenant", "the firm the clients and matters belong to");
10508
10510
  const file = required(flags, "from-file", "the clients and their matters are a document: see tools/admin/examples/matters-import.json");
10509
10511
  const { raw, parsed } = readDocument(file, MatterImportSchema, "a matters import (clients, each with its matters)");
10510
- const answer = await call(run2.api, "POST", tenantPath(tenant, "/matters/import"), raw);
10512
+ const answer = await firmCall(run2, tenant, "POST", "/v1/matters/import", raw);
10511
10513
  if (answer.status !== 200)
10512
10514
  return refused(run2, answer, [actingHead(tenant, answer)]);
10513
10515
  const report = ImportReportSchema.parse(answer.body);
@@ -10583,11 +10585,11 @@ function reviewerChoice(flags) {
10583
10585
  async function runConnector(run2, subcommand) {
10584
10586
  const { flags, environment } = run2;
10585
10587
  const tenantId = required(flags, "firm", "every connector command names the firm it is for");
10586
- const path = (rest) => tenantPath(tenantId, `/connector${rest}`);
10588
+ const path = (rest) => `/v1/connector${rest}`;
10587
10589
  const head = (answer) => [actingHead(tenantId, answer)];
10588
10590
  if (subcommand === "connect") {
10589
10591
  const body = await connectBody(run2);
10590
- const answer = await call(run2.api, "PUT", path(""), body);
10592
+ const answer = await firmCall(run2, tenantId, "PUT", path(""), body);
10591
10593
  if (answer.status !== 200) {
10592
10594
  const lead = answer.status === 409 && problemOf(answer).type !== "urn:six-minute:problem:no-acting-member" ? ["disconnect first: this firm is on another practice system, and there is one at a time."] : [];
10593
10595
  return refused(run2, answer, [...head(answer), ...lead]);
@@ -10613,7 +10615,7 @@ async function runConnector(run2, subcommand) {
10613
10615
  });
10614
10616
  const unbind = flags.repeated.get("unbind") ?? [];
10615
10617
  const confirm = switched(flags, "confirm");
10616
- const answer = await call(run2.api, "POST", path("/team/apply"), { bind, unbind, confirm });
10618
+ const answer = await firmCall(run2, tenantId, "POST", path("/team/apply"), { bind, unbind, confirm });
10617
10619
  if (answer.status !== 200)
10618
10620
  return refused(run2, answer, head(answer));
10619
10621
  const done = TeamApplyResultSchema.parse(answer.body);
@@ -10630,7 +10632,7 @@ async function runConnector(run2, subcommand) {
10630
10632
  }
10631
10633
  if (subcommand === "reviewer") {
10632
10634
  const choice = reviewerChoice(flags);
10633
- const connector2 = await call(run2.api, "GET", path(""));
10635
+ const connector2 = await firmCall(run2, tenantId, "GET", path(""));
10634
10636
  if (connector2.status !== 200)
10635
10637
  return refused(run2, connector2, head(connector2));
10636
10638
  const current = ConnectorSummarySchema.parse(connector2.body);
@@ -10642,7 +10644,7 @@ async function runConnector(run2, subcommand) {
10642
10644
  }
10643
10645
  let reviewer = { mode: "timekeeper" };
10644
10646
  if (choice.mode === "person") {
10645
- const team = await call(run2.api, "GET", path("/team"));
10647
+ const team = await firmCall(run2, tenantId, "GET", path("/team"));
10646
10648
  if (team.status !== 200)
10647
10649
  return refused(run2, team, head(team));
10648
10650
  const row = TeamProposalSchema.parse(team.body).rows.find((r) => r.external_ref === choice.external_ref);
@@ -10651,7 +10653,7 @@ async function runConnector(run2, subcommand) {
10651
10653
  }
10652
10654
  reviewer = { mode: "person", external_ref: row.external_ref, name: row.name };
10653
10655
  }
10654
- const answer = await call(run2.api, "PUT", path("/settings"), { reviewer });
10656
+ const answer = await firmCall(run2, tenantId, "PUT", path("/settings"), { reviewer });
10655
10657
  if (answer.status !== 200)
10656
10658
  return refused(run2, answer, head(answer));
10657
10659
  const summary = ConnectorSummarySchema.parse(answer.body);
@@ -10663,32 +10665,32 @@ async function runConnector(run2, subcommand) {
10663
10665
  if (auto === switched(flags, "review")) {
10664
10666
  throw new AdminUsageError("connector approval takes one of --review (the draft waits in the practice system until it is approved) " + "or --auto (it is written as approved time, with no draft)");
10665
10667
  }
10666
- const answer = await call(run2.api, "PUT", path("/approval"), { member_id: member, mode: auto ? "auto" : "review" });
10668
+ const answer = await firmCall(run2, tenantId, "PUT", path("/approval"), { member_id: member, mode: auto ? "auto" : "review" });
10667
10669
  if (answer.status !== 200)
10668
10670
  return refused(run2, answer, head(answer));
10669
10671
  const summary = ConnectorSummarySchema.parse(answer.body);
10670
10672
  return render(run2, { connector: summary }, [...head(answer), ...summaryLines(summary)]);
10671
10673
  }
10672
10674
  if (subcommand === "status") {
10673
- const answer = await call(run2.api, "GET", path(""));
10675
+ const answer = await firmCall(run2, tenantId, "GET", path(""));
10674
10676
  if (answer.status !== 200)
10675
10677
  return refused(run2, answer, head(answer));
10676
10678
  const summary = ConnectorSummarySchema.parse(answer.body);
10677
- const answered = await call(run2.api, "GET", path("/team"));
10679
+ const answered = await firmCall(run2, tenantId, "GET", path("/team"));
10678
10680
  if (answered.status !== 200 && answered.status !== 404)
10679
10681
  return refused(run2, answered, head(answer));
10680
10682
  const team = answered.status === 200 ? TeamProposalSchema.parse(answered.body) : null;
10681
10683
  return render(run2, { connector: summary, team }, [...head(answer), ...connectorLines(summary, team, [])]);
10682
10684
  }
10683
10685
  if (subcommand === "sync") {
10684
- const answer = await call(run2.api, "POST", path("/sync"));
10686
+ const answer = await firmCall(run2, tenantId, "POST", path("/sync"));
10685
10687
  if (answer.status !== 200)
10686
10688
  return refused(run2, answer, head(answer));
10687
10689
  const report = SyncReportSchema.parse(answer.body);
10688
10690
  return render(run2, { sync: report }, [...head(answer), ...syncLines(report)]);
10689
10691
  }
10690
10692
  if (subcommand === "disconnect") {
10691
- const answer = await call(run2.api, "DELETE", path(""));
10693
+ const answer = await firmCall(run2, tenantId, "DELETE", path(""));
10692
10694
  if (answer.status !== 204)
10693
10695
  return refused(run2, answer, head(answer));
10694
10696
  return render(run2, { disconnected: tenantId }, [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unisonlabs/sixminute-admin",
3
- "version": "0.1.1391-next",
3
+ "version": "0.1.1392-next",
4
4
  "description": "Sixminute operator tool: the admin commands of the Sixminute API, run with your own operator sign-in.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {