@north-light/api 0.3.757 → 0.3.759
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/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/grants/mirror.js +2 -2
- package/dist/core/grants/shadow.js +25 -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/daemon/api/handlers/providers.js +6 -4
- 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.80";
|
|
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.80';
|
|
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`. */
|
|
@@ -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
|
});
|
|
@@ -150,7 +150,7 @@ export async function otherLiveGrantOfApp(app, sub) {
|
|
|
150
150
|
}
|
|
151
151
|
/** Contract 1's `<id>` grammar, shared by provider ids and group ids. */
|
|
152
152
|
const ID = '[A-Za-z0-9_-]{1,64}';
|
|
153
|
-
const PROVIDER_SCOPE = new RegExp(`^(${ID}):(${ID})$`);
|
|
153
|
+
const PROVIDER_SCOPE = new RegExp(`^(${ID}):(${ID}|\\*)$`);
|
|
154
154
|
/** Every provider id a scope of an active grant's resolved set names: a
|
|
155
155
|
* `<id>:<group>` string whose id is not `crtr` (the runtime's own namespace). */
|
|
156
156
|
export function providerIdsFromGrants(grants) {
|
|
@@ -180,7 +180,7 @@ export async function activeProviderIds() {
|
|
|
180
180
|
SELECT DISTINCT e->>'scope' AS scope FROM (
|
|
181
181
|
SELECT t::jsonb AS j FROM (SELECT DISTINCT resolved_scopes_json AS t FROM grants WHERE ${ACTIVE_COMPUTED}${localOnly()}${scope.sql}) d OFFSET 0) p
|
|
182
182
|
CROSS JOIN LATERAL jsonb_array_elements(CASE WHEN jsonb_typeof(p.j) = 'array' THEN p.j ELSE '[]' END) e) s
|
|
183
|
-
CROSS JOIN LATERAL regexp_match(s.scope, '^(${ID})
|
|
183
|
+
CROSS JOIN LATERAL regexp_match(s.scope, '^(${ID}):(?:${ID}|\\*)$') m
|
|
184
184
|
WHERE m[1] <> 'crtr'`).all(...scope.args);
|
|
185
185
|
return rows.map((row) => row.id).sort();
|
|
186
186
|
}
|
|
@@ -69,7 +69,8 @@ async function compare(stored) {
|
|
|
69
69
|
}
|
|
70
70
|
// The directory may still send the older `'user'`/`'app'` payer; the mirror stores it as a principal.
|
|
71
71
|
const liveSide = { ...live, payer: principalPayer(live['payer'], stored.sub, stored.grantee) };
|
|
72
|
-
const
|
|
72
|
+
const storedSide = { ...stored, resolved_scopes: compactLike(stored.resolved_scopes, live['resolved_scopes']) };
|
|
73
|
+
const fields = COMPARED.filter((key) => canonicalJson(liveSide[key] ?? null) !== canonicalJson(storedSide[key] ?? null));
|
|
73
74
|
if (fields.length === 0) {
|
|
74
75
|
shadowCounts.agree++;
|
|
75
76
|
return;
|
|
@@ -77,6 +78,29 @@ async function compare(stored) {
|
|
|
77
78
|
shadowCounts.disagree++;
|
|
78
79
|
warn(`grant_shadow disagree ${JSON.stringify({ grant: stored.id, sub: stored.sub, rev: stored.rev, fields })}`);
|
|
79
80
|
}
|
|
81
|
+
// The live answer may hold `<provider>:*` where the stored column still lists each group (phase 4). Fold the stored groups of each such
|
|
82
|
+
// provider into its wildcard, keeping the first group's mode and position, so the two forms compare equal when they name the same providers. A group the live answer still names (an `own` group) stays.
|
|
83
|
+
function compactLike(stored, live) {
|
|
84
|
+
if (!Array.isArray(live))
|
|
85
|
+
return stored;
|
|
86
|
+
const named = new Set(live.flatMap((entry) => {
|
|
87
|
+
const scope = entry?.scope;
|
|
88
|
+
return typeof scope === 'string' ? [scope] : [];
|
|
89
|
+
}));
|
|
90
|
+
const wild = new Set([...named].filter((scope) => scope.endsWith(':*')).map((scope) => scope.slice(0, -2)));
|
|
91
|
+
if (wild.size === 0)
|
|
92
|
+
return stored;
|
|
93
|
+
const seen = new Set();
|
|
94
|
+
return stored.flatMap((entry) => {
|
|
95
|
+
const provider = entry.scope.slice(0, entry.scope.indexOf(':'));
|
|
96
|
+
if (provider === 'crtr' || !wild.has(provider) || named.has(entry.scope))
|
|
97
|
+
return [entry];
|
|
98
|
+
if (seen.has(provider))
|
|
99
|
+
return [];
|
|
100
|
+
seen.add(provider);
|
|
101
|
+
return [{ ...entry, scope: `${provider}:*` }];
|
|
102
|
+
});
|
|
103
|
+
}
|
|
80
104
|
let summaryTimer;
|
|
81
105
|
let reported = { agree: 0, disagree: 0, lagging: 0, error: 0 };
|
|
82
106
|
// One greppable line a minute while checks are happening: `grep grant_shadow_summary`; sum `disagree` across pods over 7 days.
|
|
@@ -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
|
|
@@ -68,7 +68,7 @@ export function callerFromApp(principal) {
|
|
|
68
68
|
return { class: 'app', sub: principal.sub, grantee: principal.grantee, client_id: principal.client_id, actor: principal.actor, resolved: principal.resolved, nodeScopes: null, run_id: null, node_id: null };
|
|
69
69
|
}
|
|
70
70
|
/** A provider scope `<provider>:<group>` (the identity grammar's `provider`
|
|
71
|
-
* selector kind).
|
|
71
|
+
* selector kind). It is held by itself or by the wildcard `<provider>:*`. */
|
|
72
72
|
const PROVIDER_SCOPE = /^([A-Za-z0-9_-]{1,64}):([A-Za-z0-9_-]{1,64})$/;
|
|
73
73
|
function isProviderScope(scope) {
|
|
74
74
|
const match = PROVIDER_SCOPE.exec(scope);
|
|
@@ -87,13 +87,15 @@ function heldSet(scopes) {
|
|
|
87
87
|
return set;
|
|
88
88
|
}
|
|
89
89
|
/** `scopeAllowed` with the provider-scope case answered by set membership:
|
|
90
|
-
* `covers(held, '<p>:<g>')` is true only for `held
|
|
90
|
+
* `covers(held, '<p>:<g>')` is true only for `held` = `<p>:<g>` or `<p>:*`, so the
|
|
91
91
|
* answer is identical and costs O(1) instead of a selector parse per held scope. */
|
|
92
92
|
function holds(scopes, scope) {
|
|
93
93
|
if (scopes === null)
|
|
94
94
|
return true;
|
|
95
|
-
if (isProviderScope(scope))
|
|
96
|
-
|
|
95
|
+
if (isProviderScope(scope)) {
|
|
96
|
+
const set = heldSet(scopes);
|
|
97
|
+
return set.has(scope) || set.has(`${scope.slice(0, scope.indexOf(':'))}:*`);
|
|
98
|
+
}
|
|
97
99
|
return scopeAllowed(scopes, scope);
|
|
98
100
|
}
|
|
99
101
|
/** Does the caller hold `<provider>:<group>`? Both the resolved set and a
|
|
@@ -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.759",
|
|
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",
|