@north-light/api 0.3.756 → 0.3.758
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/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/commands/profile/new.js +2 -2
- package/dist/commands/profile/project.js +2 -1
- package/dist/commands/sys/import/move.d.ts +5 -0
- package/dist/commands/sys/import/move.js +1 -1
- package/dist/commands/sys/import/retry.d.ts +1 -0
- package/dist/commands/sys/import/retry.js +38 -0
- package/dist/commands/sys/import/start.js +2 -1
- package/dist/core/import/export/cloud.d.ts +1 -0
- package/dist/core/import/export/cloud.js +1 -0
- package/dist/core/import/load/prepare.js +2 -2
- package/dist/core/profiles/manifest.js +12 -18
- package/dist/core/profiles/project-dir.d.ts +3 -0
- package/dist/core/profiles/project-dir.js +20 -0
- package/dist/daemon/api/operations.js +1 -0
- package/package.json +1 -1
package/dist/api/contract.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The contract level this build serves and requires. Written by `scripts/contract.mjs release`; never edit by hand. */
|
|
2
|
-
export declare const CONTRACT_LEVEL = "1.
|
|
2
|
+
export declare const CONTRACT_LEVEL = "1.79";
|
|
3
3
|
/** Request header naming the one contract level the caller needs, e.g. `1.3`. Optional: absent means no check. */
|
|
4
4
|
export declare const REQUIRED_CONTRACT_HEADER = "Crouter-Required-Contract";
|
|
5
5
|
/** Response header listing the contract levels the server serves, comma-separated, one per major, e.g. `1.3`. */
|
package/dist/api/contract.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
//
|
|
13
13
|
// PURITY (spec §3.1): Node built-ins + `src/api/*` only.
|
|
14
14
|
/** The contract level this build serves and requires. Written by `scripts/contract.mjs release`; never edit by hand. */
|
|
15
|
-
export const CONTRACT_LEVEL = '1.
|
|
15
|
+
export const CONTRACT_LEVEL = '1.79';
|
|
16
16
|
/** Request header naming the one contract level the caller needs, e.g. `1.3`. Optional: absent means no check. */
|
|
17
17
|
export const REQUIRED_CONTRACT_HEADER = 'Crouter-Required-Contract';
|
|
18
18
|
/** Response header listing the contract levels the server serves, comma-separated, one per major, e.g. `1.3`. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineLeaf } from '../../core/command.js';
|
|
2
2
|
import { usage } from '../../core/errors.js';
|
|
3
|
-
import {
|
|
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:
|
|
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:
|
|
52
|
+
add_project: dir !== undefined ? { path: resolveExistingProjectDir(dir) } : { repo: repo },
|
|
52
53
|
});
|
|
53
54
|
return { profile_id: updated.id, projects: updated.projects };
|
|
54
55
|
},
|
|
@@ -15,6 +15,11 @@ export declare function endDrainConfirmed(client: {
|
|
|
15
15
|
export declare function settleDrainAtEnd(done: boolean, client: {
|
|
16
16
|
endDaemonDrain(): Promise<unknown>;
|
|
17
17
|
}): Promise<void>;
|
|
18
|
+
/** After `load` was sent the run's outcome is unknown until the control plane says it: wait for `done`, throw on `failed` / `rolled_back`, and keep asking
|
|
19
|
+
* while the control plane cannot be reached or answers an error (a lost answer must never read as a failure: the account may hold the records). Only a
|
|
20
|
+
* sign-in that no longer works, or an answer the control plane will repeat, ends the wait with `move_outcome_unknown`, because asking can never succeed again. A `load` that threw while the run
|
|
21
|
+
* never left `uploading` did not start, so its error stands. */
|
|
22
|
+
export declare function awaitRunOutcome(cloud: ImportCloud, runId: string, loadError: unknown): Promise<void>;
|
|
18
23
|
export interface ExportStep {
|
|
19
24
|
name: string;
|
|
20
25
|
timings: string[];
|
|
@@ -57,7 +57,7 @@ const OUTCOME_RETRY_MAX_MS = 30_000;
|
|
|
57
57
|
* while the control plane cannot be reached or answers an error (a lost answer must never read as a failure: the account may hold the records). Only a
|
|
58
58
|
* sign-in that no longer works, or an answer the control plane will repeat, ends the wait with `move_outcome_unknown`, because asking can never succeed again. A `load` that threw while the run
|
|
59
59
|
* never left `uploading` did not start, so its error stands. */
|
|
60
|
-
async function awaitRunOutcome(cloud, runId, loadError) {
|
|
60
|
+
export async function awaitRunOutcome(cloud, runId, loadError) {
|
|
61
61
|
let gap = 2000;
|
|
62
62
|
for (;;) {
|
|
63
63
|
let state;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const retry: import("../../../core/command.js").LeafDef;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// `crtr sys import retry <run_id>`: loads a failed import again from the bundle its failure kept.
|
|
2
|
+
import { defineLeaf } from '../../../core/command.js';
|
|
3
|
+
import { usage } from '../../../core/errors.js';
|
|
4
|
+
import { ImportCloud } from '../../../core/import/export/cloud.js';
|
|
5
|
+
import { controlPlaneUrl, personBearer } from '../../../core/directory/person-credential.js';
|
|
6
|
+
import { awaitRunOutcome, defaultDirectoryUrl } from './move.js';
|
|
7
|
+
export const retry = defineLeaf({
|
|
8
|
+
name: 'retry',
|
|
9
|
+
description: 'load a failed import again from the bundle it already uploaded',
|
|
10
|
+
whenToUse: 'an import failed while Northlight was loading it (a refused or conflicting row) and the cause is fixed: no new upload and no new confirm code',
|
|
11
|
+
help: {
|
|
12
|
+
name: 'sys import retry',
|
|
13
|
+
summary: 're-queue a failed run so Northlight loads its kept upload again, then wait for the outcome',
|
|
14
|
+
guide: 'Works for a run that failed before its copy committed and whose upload is under 7 days old (Northlight deletes older ones; run the import again then). The bundle is what was uploaded, so rows this computer changed since are not in it. Prints the final state, or the new failure.',
|
|
15
|
+
params: [
|
|
16
|
+
{ kind: 'positional', name: 'run_id', type: 'string', required: true, constraint: 'The failed import run (`imp_…`).' },
|
|
17
|
+
{ kind: 'flag', name: 'api-url', type: 'string', required: false, constraint: 'Control plane base URL; default is the one the sign-in is for.' },
|
|
18
|
+
],
|
|
19
|
+
output: [
|
|
20
|
+
{ name: 'run_id', type: 'string', required: true, constraint: 'The import run.' },
|
|
21
|
+
{ name: 'state', type: 'string', required: true, constraint: 'Final state of the run, `done`.' },
|
|
22
|
+
],
|
|
23
|
+
outputKind: 'object',
|
|
24
|
+
effects: ['Moves the run from `failed` back to `loading` on the control plane; nothing local changes.'],
|
|
25
|
+
},
|
|
26
|
+
run: async (input) => {
|
|
27
|
+
const runId = String(input['run_id'] ?? '');
|
|
28
|
+
if (runId === '')
|
|
29
|
+
throw usage('name the failed run: crtr sys import retry <run_id>');
|
|
30
|
+
const directoryUrl = defaultDirectoryUrl();
|
|
31
|
+
const apiUrl = input.apiUrl === undefined ? await controlPlaneUrl(directoryUrl) : String(input.apiUrl);
|
|
32
|
+
const cloud = new ImportCloud(apiUrl, () => personBearer(directoryUrl));
|
|
33
|
+
await cloud.retry(runId);
|
|
34
|
+
await awaitRunOutcome(cloud, runId, undefined);
|
|
35
|
+
return { run_id: runId, state: 'done' };
|
|
36
|
+
},
|
|
37
|
+
render: (r) => `<import run="${r['run_id']}" state="${r['state']}"/>`,
|
|
38
|
+
});
|
|
@@ -9,6 +9,7 @@ import { showSignIn } from '../signin.js';
|
|
|
9
9
|
import { insideBroker } from '../join.js';
|
|
10
10
|
import { defaultDirectoryUrl, exportRun, settleEarlierMove, finishMove, runMove } from './move.js';
|
|
11
11
|
import { resume } from './resume.js';
|
|
12
|
+
import { retry } from './retry.js';
|
|
12
13
|
/** Set by `crtr sys signin` on the detached exporter it starts from inside a node: the signin process, which the exporter outlives before it drains,
|
|
13
14
|
* so it is never in a broker's process tree. */
|
|
14
15
|
export const WAIT_FOR_PID_ENV = 'CRTR_IMPORT_WAIT_PID';
|
|
@@ -88,5 +89,5 @@ export const sysImportBranch = defineBranch({
|
|
|
88
89
|
description: 'move this runtime into the person\'s Northlight account',
|
|
89
90
|
whenToUse: 'importing this computer or hosted runtime into Northlight',
|
|
90
91
|
help: { name: 'sys import', summary: 'export this runtime to Northlight', model: 'The exporter pauses the local daemon, uploads a bundle the control plane loads into the shared database, and on a computer switches it to the machine role.' },
|
|
91
|
-
children: [start, resume],
|
|
92
|
+
children: [start, resume, retry],
|
|
92
93
|
});
|
|
@@ -25,6 +25,7 @@ export declare class ImportCloud {
|
|
|
25
25
|
uploadUrls(run: string, keys: string[]): Promise<ImportUploadUrlsDTO>;
|
|
26
26
|
putStore(run: string, name: ImportStoreNameDTO, body: unknown): Promise<void>;
|
|
27
27
|
load(run: string): Promise<ImportRunDTO>;
|
|
28
|
+
retry(run: string): Promise<ImportRunDTO>;
|
|
28
29
|
get(run: string): Promise<ImportRunDTO>;
|
|
29
30
|
/** `rotate` replaces a credential already issued for this run's machine (without it a second call answers 409 `credential_exists`). */
|
|
30
31
|
machineCredential(run: string, rotate?: boolean): Promise<{
|
|
@@ -101,6 +101,7 @@ export class ImportCloud {
|
|
|
101
101
|
uploadUrls(run, keys) { return this.call('POST', `/v1/imports/${run}/upload-urls`, { keys }, true); }
|
|
102
102
|
putStore(run, name, body) { return this.call('PUT', `/v1/imports/${run}/stores/${name}`, body, true); }
|
|
103
103
|
load(run) { return this.call('POST', `/v1/imports/${run}/load`, {}); }
|
|
104
|
+
retry(run) { return this.call('POST', `/v1/imports/${run}/retry`, {}); }
|
|
104
105
|
get(run) { return this.call('GET', `/v1/imports/${run}`); }
|
|
105
106
|
/** `rotate` replaces a credential already issued for this run's machine (without it a second call answers 409 `credential_exists`). */
|
|
106
107
|
machineCredential(run, rotate = false) { return this.call('POST', `/v1/imports/${run}/machine-credential${rotate ? '?rotate=1' : ''}`, {}); }
|
|
@@ -211,8 +211,8 @@ export async function takeRepoSyncedDocuments(db, schema, target) {
|
|
|
211
211
|
}
|
|
212
212
|
/** Columns that record when a fact was written, not what it says. A fact row (an edge, a relation) the target already holds under the same key is present
|
|
213
213
|
* whatever its `created_at`: shipped documents, their links and readers, and the person's `acts_for` are written by the target's own publication and sign-in
|
|
214
|
-
* at another time. The copy step skips the held key (`ON CONFLICT DO NOTHING`); `written_as`
|
|
215
|
-
const WRITTEN_AT = { edges: ['created_at'], relations: ['created_at'] };
|
|
214
|
+
* at another time. The copy step skips the held key (`ON CONFLICT DO NOTHING`); `written_as` still has to agree. A relation's key is the whole fact, so its `written_by` is not compared: the target's row stands (the person's `acts_for` is written by sign-in, a bundle's by the source). */
|
|
215
|
+
const WRITTEN_AT = { edges: ['created_at'], relations: ['created_at', 'written_by'] };
|
|
216
216
|
/** A `charges` id is the idempotency key (`receipt:<provider>:<receipt id>`: "a repeat of an existing id adds nothing", ledger/types.ts): when the target already holds
|
|
217
217
|
* it, the charge is the same one and the copy step skips it (`ON CONFLICT DO NOTHING`; the target's row stands). What the charge says is who paid, what it
|
|
218
218
|
* metered and what it cost; when and how each side recorded or priced it (`at`, `billed_usd`, `priced_at`, `node`, `account`, `price_id`, the admission and cost
|
|
@@ -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 {
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
if (!
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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:
|
|
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 =
|
|
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
|
+
}
|
|
@@ -207,6 +207,7 @@ export const OPERATIONS = [
|
|
|
207
207
|
{ name: 'import.store', method: 'PUT', path: '/v1/imports/:run_id/stores/:name', classes: ['person', 'import'], resource: 'none' },
|
|
208
208
|
{ name: 'import.load', method: 'POST', path: '/v1/imports/:run_id/load', classes: ['person', 'import'], resource: 'none' },
|
|
209
209
|
{ name: 'import.get', method: 'GET', path: '/v1/imports/:run_id', classes: ['person', 'import'], resource: 'none' },
|
|
210
|
+
{ name: 'import.retry', method: 'POST', path: '/v1/imports/:run_id/retry', classes: ['person'], resource: 'none' },
|
|
210
211
|
{ name: 'import.rollback', method: 'POST', path: '/v1/imports/:run_id/rollback', classes: ['person'], resource: 'none' },
|
|
211
212
|
{ name: 'machine.register', method: 'POST', path: '/v1/machines', classes: ['person'], resource: 'none' },
|
|
212
213
|
{ name: 'machine.revoke', method: 'DELETE', path: '/v1/machines/:environment_id', classes: ['person'], resource: 'none' },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.758",
|
|
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",
|