@north-light/api 0.3.756 → 0.3.757

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.
@@ -1,6 +1,6 @@
1
1
  import { defineLeaf } from '../../core/command.js';
2
2
  import { usage } from '../../core/errors.js';
3
- import { resolve } from 'node:path';
3
+ import { resolveExistingProjectDir } from '../../core/profiles/project-dir.js';
4
4
  import { cliClient } from '../api-client.js';
5
5
  import { resolveMetaPairs } from './meta.js';
6
6
  export const newLeaf = defineLeaf({
@@ -87,7 +87,7 @@ export const newLeaf = defineLeaf({
87
87
  throw usage('provide `--name <name>` to create a profile, or `--root` to provision the stable root profile.');
88
88
  return newProfileOutput(await cliClient().createProfile({
89
89
  name,
90
- ...(project !== undefined ? { projects: [{ path: resolve(project) }] } : {}),
90
+ ...(project !== undefined ? { projects: [{ path: resolveExistingProjectDir(project) }] } : {}),
91
91
  ...(repos.length > 0 ? { repositories: repos } : {}),
92
92
  ...(defaultKind !== undefined ? { default_kind: defaultKind } : {}),
93
93
  ...(Object.keys(metadata).length > 0 ? { metadata } : {}),
@@ -1,6 +1,7 @@
1
1
  // `crtr profile project` manages purview relationships and per-owner automatic delivery limits.
2
2
  import { defineLeaf, defineBranch } from '../../core/command.js';
3
3
  import { resolve } from 'node:path';
4
+ import { resolveExistingProjectDir } from '../../core/profiles/project-dir.js';
4
5
  import { usage } from '../../core/errors.js';
5
6
  import { cliClient } from '../api-client.js';
6
7
  import { resolveProfileViaDaemon } from './daemon-profiles.js';
@@ -48,7 +49,7 @@ const addLeaf = defineLeaf({
48
49
  if ((dir === undefined) === (repo === undefined))
49
50
  throw usage('pass exactly one of --dir and --repo', { next: 'Use --dir <directory> for a folder or --repo <handle> for a repo with no folder.' });
50
51
  const updated = await cliClient().updateProfile(id, {
51
- add_project: dir !== undefined ? { path: resolve(dir) } : { repo: repo },
52
+ add_project: dir !== undefined ? { path: resolveExistingProjectDir(dir) } : { repo: repo },
52
53
  });
53
54
  return { profile_id: updated.id, projects: updated.projects };
54
55
  },
@@ -1,7 +1,8 @@
1
1
  // Profile definitions live in scoped state; memory and environment have separate roots.
2
2
  import { randomUUID } from 'node:crypto';
3
- import { existsSync, realpathSync, rmSync, statSync } from 'node:fs';
4
- import { resolve as resolvePath } from 'node:path';
3
+ import { realpathSync, rmSync } from 'node:fs';
4
+ import { isAbsolute, resolve as resolvePath } from 'node:path';
5
+ import { resolveExistingProjectDir } from './project-dir.js';
5
6
  import { SCHEMA_VERSION } from '../../types.js';
6
7
  import { profileSpace } from '../layout.js';
7
8
  import { PROFILE_PROJECT_MEMORY_VALUES } from '../../api/dto/profiles.js';
@@ -165,20 +166,13 @@ export function matchProfileOperand(all, operand, key) {
165
166
  }
166
167
  // Project dirs — resolved to absolute real paths, must exist + be a directory
167
168
  // on add/create, deduped by real path, stored in manifest order.
168
- function resolveExistingProjectDir(dir) {
169
- const abs = resolvePath(dir);
170
- if (!existsSync(abs) || !statSync(abs).isDirectory()) {
171
- throw usage(`project directory does not exist or is not a directory: ${dir}`, {
172
- received: dir,
173
- next: 'Pass an existing directory path.',
174
- });
175
- }
176
- try {
177
- return realpathSync(abs);
178
- }
179
- catch {
180
- return abs;
181
- }
169
+ /** A cloud role cannot see the caller's disk: the caller's CLI already resolved the path on its own machine, so it is stored as sent. */
170
+ function storedProjectDir(dir) {
171
+ if (!isCloudRole())
172
+ return resolveExistingProjectDir(dir);
173
+ if (!isAbsolute(dir))
174
+ throw usage(`project directory must be an absolute path: ${dir}`, { received: dir });
175
+ return dir;
182
176
  }
183
177
  /** First-wins by resolved path; by repo only among entries with no path. A folder entry for a repo that has a repo-only entry merges into it
184
178
  * (one entry, both fields, the repo-only entry's position). */
@@ -342,7 +336,7 @@ export async function createProfile(name, projects = [], opts = {}) {
342
336
  if (opts.metadata !== undefined)
343
337
  assertProfileMetadata(opts.metadata);
344
338
  assertProfileProjects(projects);
345
- const resolvedProjects = dedupeProjects(projects.map((p) => ({ ...(p.repo === undefined ? {} : { repo: p.repo }), ...(p.path === undefined ? {} : { path: resolveExistingProjectDir(p.path) }) })));
339
+ const resolvedProjects = dedupeProjects(projects.map((p) => ({ ...(p.repo === undefined ? {} : { repo: p.repo }), ...(p.path === undefined ? {} : { path: storedProjectDir(p.path) }) })));
346
340
  const profileId = generateProfileId(trimmed);
347
341
  const manifest = {
348
342
  schema_version: SCHEMA_VERSION,
@@ -505,7 +499,7 @@ export async function renameProfile(profileId, name) {
505
499
  * a folder no repo identifies keeps `path` only. A listed entry with that path but no repo gains the repo in place. */
506
500
  export async function addProfileProject(profileId, dir, repo) {
507
501
  assertProfileProjects([{ path: dir, ...(repo === undefined ? {} : { repo }) }]);
508
- const resolved = resolveExistingProjectDir(dir);
502
+ const resolved = storedProjectDir(dir);
509
503
  return await mutateManifest(profileId, (m) => ({
510
504
  ...m,
511
505
  projects: dedupeProjects(m.projects.some((p) => p.path === resolved)
@@ -0,0 +1,3 @@
1
+ /** A project directory as an absolute real path; it must exist and be a directory on THIS machine's disk.
2
+ * The CLI runs this on the caller's machine before sending a path to a canvas that may live in the cloud. */
3
+ export declare function resolveExistingProjectDir(dir: string): string;
@@ -0,0 +1,20 @@
1
+ import { existsSync, realpathSync, statSync } from 'node:fs';
2
+ import { resolve as resolvePath } from 'node:path';
3
+ import { usage } from '../errors.js';
4
+ /** A project directory as an absolute real path; it must exist and be a directory on THIS machine's disk.
5
+ * The CLI runs this on the caller's machine before sending a path to a canvas that may live in the cloud. */
6
+ export function resolveExistingProjectDir(dir) {
7
+ const abs = resolvePath(dir);
8
+ if (!existsSync(abs) || !statSync(abs).isDirectory()) {
9
+ throw usage(`project directory does not exist or is not a directory: ${dir}`, {
10
+ received: dir,
11
+ next: 'Pass an existing directory path.',
12
+ });
13
+ }
14
+ try {
15
+ return realpathSync(abs);
16
+ }
17
+ catch {
18
+ return abs;
19
+ }
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.756",
3
+ "version": "0.3.757",
4
4
  "description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/api/index.js",