@plandesk/api 1.0.0 → 1.0.3

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/identity.js CHANGED
@@ -176,6 +176,14 @@ export async function backfillProjectWorkspaces(db, auth) {
176
176
  let projectsUpdated = 0;
177
177
  for (const row of result.rows) {
178
178
  const project = row;
179
+ // Only repair projects whose workspace_id does NOT reference a real team in
180
+ // their org (the placeholder column default, or a dangling id). A project
181
+ // already in a valid workspace — e.g. one legacy-upgrade/move/go-online
182
+ // placed in a non-default team — must be left alone, never reset to General.
183
+ if (project.workspace_id.length > 0 &&
184
+ (await getTeamInOrg(auth, project.workspace_id, project.org_id)) !== undefined) {
185
+ continue;
186
+ }
179
187
  const teamId = await ensureDefaultTeamForOrg(auth, project.org_id);
180
188
  if (project.workspace_id !== teamId) {
181
189
  await updateProject(db, project.id, { workspaceId: teamId });
@@ -1,5 +1,5 @@
1
1
  import { Hono } from 'hono';
2
- import type { Db } from '@plandesk/db';
2
+ import { type Db } from '@plandesk/db';
3
3
  import type { BetterAuthInstance } from '../better-auth.js';
4
4
  import type { GithubConfig } from '../github.js';
5
5
  export type AuthRouterDeps = {
@@ -1,4 +1,5 @@
1
1
  import { Hono } from 'hono';
2
+ import { listProjects } from '@plandesk/db';
2
3
  import { createOrgOwnerKey } from '../agent-keys.js';
3
4
  import { getAuthContext } from '../auth-context.js';
4
5
  import { getActiveTeamForSession, listTeamsForOrg, } from '../identity.js';
@@ -43,9 +44,15 @@ export function createAuthRouter(deps) {
43
44
  active ?? (workspaces[0] !== undefined ? workspaces[0] : null);
44
45
  }
45
46
  else {
46
- // Loopback: no session row to carry an active team default to the
47
- // first workspace (the org's default team) so the switcher still renders.
48
- activeWorkspace = workspaces[0] !== undefined ? workspaces[0] : null;
47
+ // Loopback: no session row to carry an active team. Default to the first
48
+ // workspace that actually HAS projects, so an imported/populated board
49
+ // (e.g. after legacy-upgrade --into-workspace) opens on its content
50
+ // instead of an empty default team; fall back to the first workspace.
51
+ const localProjects = await listProjects(deps.db, ctx.orgId);
52
+ const populated = new Set(localProjects.map((project) => project.workspaceId));
53
+ activeWorkspace =
54
+ workspaces.find((workspace) => populated.has(workspace.id)) ??
55
+ (workspaces[0] !== undefined ? workspaces[0] : null);
49
56
  }
50
57
  }
51
58
  return c.json({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plandesk/api",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {