@north-light/api 0.3.758 → 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
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`. */
|
|
@@ -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.
|
|
@@ -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
|
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",
|