@colixsystems/widget-sdk 0.337.0 → 0.337.1
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/README.md +6 -2
- package/dist/linter.cjs +79 -7
- package/dist/linter.js +79 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,7 +91,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
91
91
|
|
|
92
92
|
## Status
|
|
93
93
|
|
|
94
|
-
`v0.337.
|
|
94
|
+
`v0.337.1` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
95
|
+
|
|
96
|
+
### What's new in 0.337.1 (contract 1.275.0)
|
|
97
|
+
|
|
98
|
+
**The two permission-gate lint rules accept the code the contract prescribes.** `row-action-not-gated` no longer flags an `update` or `delete` of the row the widget's own `create()` just returned, as in the record-file attach flow (`const row = await create(values)`, then `upload(file, { recordId: row.id })`, then `update(row.id, …)`). That row carries no `_capabilities`, and whether its creator may edit it is set by the table's permissions. The exemption holds only while that name is bound once, so a listed `row` elsewhere in the file still needs its per-row gate. `write-not-gated-on-user` now accepts a `_capabilities` read as the gate when the widget only edits or deletes existing rows; a widget that also creates rows still gates the create on `useCanWrite(tableId)` or `useUser()`. Both findings now name the fix for each case. Fix-only: no rule was added or renamed.
|
|
95
99
|
|
|
96
100
|
### What's new in 0.337.0 (contract 1.275.0)
|
|
97
101
|
|
|
@@ -4193,7 +4197,7 @@ Pass `--manifest` to enable `style-field-unread` and the three editability rules
|
|
|
4193
4197
|
|
|
4194
4198
|
`comment-as-jsx-text` refuses a `//` or `/* */` comment written between JSX tags, where it is text the web Player shows and the native app refuses. Write it as `{/* … */}`. An error.
|
|
4195
4199
|
|
|
4196
|
-
`row-action-not-gated` flags a widget that calls `update` or `delete` from `useDatastoreMutation` without a per-row permission check: no `_capabilities` read and no `useCanWrite(tableId, { recordId })`. The table-level `useCanWrite(tableId)` only answers "may create", so a list gated on it shows Edit / Delete on rows the server will refuse. A warning.
|
|
4200
|
+
`row-action-not-gated` flags a widget that calls `update` or `delete` from `useDatastoreMutation` without a per-row permission check: no `_capabilities` read and no `useCanWrite(tableId, { recordId })`. An `update` or `delete` of the row the widget's own `create()` just returned is exempt. The table-level `useCanWrite(tableId)` only answers "may create", so a list gated on it shows Edit / Delete on rows the server will refuse. A warning.
|
|
4197
4201
|
|
|
4198
4202
|
`no-html-in-content` flags an HTML tag inside a **string** — `"<strong>"`, `"<br>"`, `"<p>…</p>"`. There is no HTML renderer on either host, so the tag reaches the reader as literal text; author formatted text with `<MarkdownInput>` and render it with `<RichText>` instead. Only string and template content is scanned, so your own `<View>` / `<Text>` JSX can never trip it. A warning for a human author, blocking for the AI widget agent.
|
|
4199
4203
|
|
package/dist/linter.cjs
CHANGED
|
@@ -1803,6 +1803,9 @@ function _writeGatedOnUserRules(source) {
|
|
|
1803
1803
|
if (!call) return [];
|
|
1804
1804
|
if (/\buseCanWrite\s*\(/.test(code)) return [];
|
|
1805
1805
|
if (_IDENTITY_GUARD_RES.some((re) => re.test(code))) return [];
|
|
1806
|
+
// Story 17720 — a widget that only edits existing rows gates each on its
|
|
1807
|
+
// `_capabilities`, which is false for a visitor too; row-action-not-gated polices it.
|
|
1808
|
+
if (/\b_capabilities\b/.test(code) && _mutationCallSites(code, "create")?.length === 0) return [];
|
|
1806
1809
|
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
1807
1810
|
return [
|
|
1808
1811
|
{
|
|
@@ -1811,9 +1814,9 @@ function _writeGatedOnUserRules(source) {
|
|
|
1811
1814
|
// Kept under ~210 chars: a finding is truncated at 300 downstream, and
|
|
1812
1815
|
// the fix instruction is the half worth keeping.
|
|
1813
1816
|
label:
|
|
1814
|
-
`writes
|
|
1815
|
-
|
|
1816
|
-
`
|
|
1817
|
+
`writes but never checks who may write - gate a create on ` +
|
|
1818
|
+
`useCanWrite(tableId) (useUser() if it needs sign-in) and an existing ` +
|
|
1819
|
+
`row's edit on row._capabilities, never a live-but-doomed control.`,
|
|
1817
1820
|
line,
|
|
1818
1821
|
snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
|
|
1819
1822
|
},
|
|
@@ -2251,21 +2254,88 @@ function _rowActionGatingRules(source) {
|
|
|
2251
2254
|
if (!call) return [];
|
|
2252
2255
|
if (/\b_capabilities\b/.test(code)) return [];
|
|
2253
2256
|
if (/\buseCanWrite\s*\([^)]*\brecordId\b/.test(code)) return [];
|
|
2257
|
+
if (_rowEditsTargetOnlyCreatedRows(code)) return [];
|
|
2254
2258
|
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
2255
2259
|
return [
|
|
2256
2260
|
{
|
|
2257
2261
|
rule: "row-action-not-gated",
|
|
2258
2262
|
severity: "warning",
|
|
2259
2263
|
label:
|
|
2260
|
-
`edits or deletes
|
|
2261
|
-
`with { includeCapabilities: true }
|
|
2262
|
-
`row._capabilities.can_write / can_delete
|
|
2264
|
+
`edits or deletes an existing row without checking its permission - read ` +
|
|
2265
|
+
`it with { includeCapabilities: true } (useDatastoreQuery or useDatastoreRecord) ` +
|
|
2266
|
+
`and offer the edit only when row._capabilities.can_write / can_delete.`,
|
|
2263
2267
|
line,
|
|
2264
2268
|
snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
|
|
2265
2269
|
},
|
|
2266
2270
|
];
|
|
2267
2271
|
}
|
|
2268
2272
|
|
|
2273
|
+
/**
|
|
2274
|
+
* Story 17720 — every update/delete targets `<name>.id` of a row the widget's
|
|
2275
|
+
* own create() returned, as the record-file attach flow does. That row carries
|
|
2276
|
+
* no `_capabilities`, and whether its creator may edit it is the table ACL's
|
|
2277
|
+
* job, so no per-row gate exists to ask for.
|
|
2278
|
+
*/
|
|
2279
|
+
function _rowEditsTargetOnlyCreatedRows(code) {
|
|
2280
|
+
const [updates, deletes, creates] = ["update", "delete", "create"].map((verb) => _mutationCallSites(code, verb));
|
|
2281
|
+
if (!updates || !deletes || !creates) return false;
|
|
2282
|
+
const sites = [...updates, ...deletes];
|
|
2283
|
+
if (sites.length === 0) return false;
|
|
2284
|
+
const created = new Set();
|
|
2285
|
+
for (const site of creates) {
|
|
2286
|
+
const before = code.slice(Math.max(0, site - 200), site);
|
|
2287
|
+
const bound = /(?<![\w$.])([A-Za-z_$][\w$]*)\s*=\s*await\s+(?:[\w$]+\s*\.\s*)?[\w$]+\s*$/.exec(before);
|
|
2288
|
+
if (bound && _boundOnlyByCreate(code, bound[1])) created.add(bound[1]);
|
|
2289
|
+
}
|
|
2290
|
+
return sites.every((open) => {
|
|
2291
|
+
const target = /^\s*([A-Za-z_$][\w$]*)\s*\??\.\s*id\s*[,)]/.exec(code.slice(open + 1));
|
|
2292
|
+
return Boolean(target) && created.has(target[1]);
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2296
|
+
// One declaration, assigned only by that create (a `let row; try { row =
|
|
2297
|
+
// await create(…) }` too). Any other binding of the name, such as a
|
|
2298
|
+
// `.map((row) =>` parameter or a destructure, could be a listed row.
|
|
2299
|
+
function _boundOnlyByCreate(code, name) {
|
|
2300
|
+
const n = name.replace(/\$/g, "\\$");
|
|
2301
|
+
const count = (re) => (code.match(re) || []).length;
|
|
2302
|
+
const emptyDeclaration = new RegExp(`\\blet\\s+${n}\\s*(?:=\\s*(?:null|undefined)\\s*)?[;,]`);
|
|
2303
|
+
return (
|
|
2304
|
+
count(new RegExp(`\\b(?:const|let|var)\\s+${n}(?![\\w$])`, "g")) === 1 &&
|
|
2305
|
+
count(new RegExp(`(?<![\\w$.])${n}\\s*=(?![=>])`, "g")) ===
|
|
2306
|
+
1 + count(new RegExp(`\\blet\\s+${n}\\s*=\\s*(?:null|undefined)\\b`, "g")) &&
|
|
2307
|
+
(count(new RegExp(`\\bconst\\s+${n}\\s*=\\s*await\\b`, "g")) === 1 || emptyDeclaration.test(code)) &&
|
|
2308
|
+
count(new RegExp(`(?<![\\w$.])${n}\\s*(?:=>|[-+*/%&|^?]{1,3}=)`, "g")) === 0 &&
|
|
2309
|
+
count(new RegExp(`\\bfor\\s*\\(\\s*${n}\\s+(?:of|in)\\b`, "g")) === 0 &&
|
|
2310
|
+
count(new RegExp(`[({\\[,:]\\s*(?:\\.\\.\\.)?${n}\\s*[,)}\\]]`, "g")) === 0
|
|
2311
|
+
);
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
/**
|
|
2315
|
+
* Index of the `(` of each call the widget makes to `verb` on a
|
|
2316
|
+
* useDatastoreMutation() result: `verb(` through its destructured local, or
|
|
2317
|
+
* `name.verb(` on a named mutation object. Null when a local cannot be read.
|
|
2318
|
+
*/
|
|
2319
|
+
function _mutationCallSites(code, verb) {
|
|
2320
|
+
const callees = [];
|
|
2321
|
+
for (const call of _mutationHookCalls(code)) {
|
|
2322
|
+
if (!call.destructured) {
|
|
2323
|
+
callees.push(`(?<![\\w$])${call.name.replace(/\$/g, "\\$")}\\s*\\.\\s*${verb}`);
|
|
2324
|
+
continue;
|
|
2325
|
+
}
|
|
2326
|
+
for (const entry of call.destructured.split(",")) {
|
|
2327
|
+
const [key, local = key] = entry.split(":").map((part) => part.trim());
|
|
2328
|
+
if (key !== verb) continue;
|
|
2329
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(local)) return null;
|
|
2330
|
+
callees.push(`(?<![\\w$.])${local.replace(/\$/g, "\\$")}`);
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
if (callees.length === 0) return [];
|
|
2334
|
+
return [...code.matchAll(new RegExp(`(?:${callees.join("|")})\\s*\\(`, "g"))].map(
|
|
2335
|
+
(m) => m.index + m[0].length - 1,
|
|
2336
|
+
);
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2269
2339
|
// The useDatastoreMutation() call whose update or delete the widget uses,
|
|
2270
2340
|
// either as `m.update(` / `m.delete(` or destructured `{ update, delete }`.
|
|
2271
2341
|
function _rowMutationCall(code) {
|
|
@@ -2314,7 +2384,9 @@ function _mutationHookCalls(code) {
|
|
|
2314
2384
|
tails.set(close, _MUTATION_TAIL_RE.test(code) ? _MUTATION_TAIL_RE.lastIndex : -1);
|
|
2315
2385
|
}
|
|
2316
2386
|
if (tails.get(close) !== -1) {
|
|
2317
|
-
|
|
2387
|
+
// The run from an enclosing body brace holds its statements too.
|
|
2388
|
+
const open = code.lastIndexOf("{", close);
|
|
2389
|
+
destructured = { index: open, destructured: code.slice(open + 1, close) };
|
|
2318
2390
|
break;
|
|
2319
2391
|
}
|
|
2320
2392
|
}
|
package/dist/linter.js
CHANGED
|
@@ -1798,6 +1798,9 @@ function _writeGatedOnUserRules(source) {
|
|
|
1798
1798
|
if (!call) return [];
|
|
1799
1799
|
if (/\buseCanWrite\s*\(/.test(code)) return [];
|
|
1800
1800
|
if (_IDENTITY_GUARD_RES.some((re) => re.test(code))) return [];
|
|
1801
|
+
// Story 17720 — a widget that only edits existing rows gates each on its
|
|
1802
|
+
// `_capabilities`, which is false for a visitor too; row-action-not-gated polices it.
|
|
1803
|
+
if (/\b_capabilities\b/.test(code) && _mutationCallSites(code, "create")?.length === 0) return [];
|
|
1801
1804
|
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
1802
1805
|
return [
|
|
1803
1806
|
{
|
|
@@ -1806,9 +1809,9 @@ function _writeGatedOnUserRules(source) {
|
|
|
1806
1809
|
// Kept under ~210 chars: a finding is truncated at 300 downstream, and
|
|
1807
1810
|
// the fix instruction is the half worth keeping.
|
|
1808
1811
|
label:
|
|
1809
|
-
`writes
|
|
1810
|
-
|
|
1811
|
-
`
|
|
1812
|
+
`writes but never checks who may write - gate a create on ` +
|
|
1813
|
+
`useCanWrite(tableId) (useUser() if it needs sign-in) and an existing ` +
|
|
1814
|
+
`row's edit on row._capabilities, never a live-but-doomed control.`,
|
|
1812
1815
|
line,
|
|
1813
1816
|
snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
|
|
1814
1817
|
},
|
|
@@ -2246,21 +2249,88 @@ function _rowActionGatingRules(source) {
|
|
|
2246
2249
|
if (!call) return [];
|
|
2247
2250
|
if (/\b_capabilities\b/.test(code)) return [];
|
|
2248
2251
|
if (/\buseCanWrite\s*\([^)]*\brecordId\b/.test(code)) return [];
|
|
2252
|
+
if (_rowEditsTargetOnlyCreatedRows(code)) return [];
|
|
2249
2253
|
const line = code.slice(0, call.index).split(/\r?\n/).length;
|
|
2250
2254
|
return [
|
|
2251
2255
|
{
|
|
2252
2256
|
rule: "row-action-not-gated",
|
|
2253
2257
|
severity: "warning",
|
|
2254
2258
|
label:
|
|
2255
|
-
`edits or deletes
|
|
2256
|
-
`with { includeCapabilities: true }
|
|
2257
|
-
`row._capabilities.can_write / can_delete
|
|
2259
|
+
`edits or deletes an existing row without checking its permission - read ` +
|
|
2260
|
+
`it with { includeCapabilities: true } (useDatastoreQuery or useDatastoreRecord) ` +
|
|
2261
|
+
`and offer the edit only when row._capabilities.can_write / can_delete.`,
|
|
2258
2262
|
line,
|
|
2259
2263
|
snippet: (source.split(/\r?\n/)[line - 1] || "").trim().slice(0, 200),
|
|
2260
2264
|
},
|
|
2261
2265
|
];
|
|
2262
2266
|
}
|
|
2263
2267
|
|
|
2268
|
+
/**
|
|
2269
|
+
* Story 17720 — every update/delete targets `<name>.id` of a row the widget's
|
|
2270
|
+
* own create() returned, as the record-file attach flow does. That row carries
|
|
2271
|
+
* no `_capabilities`, and whether its creator may edit it is the table ACL's
|
|
2272
|
+
* job, so no per-row gate exists to ask for.
|
|
2273
|
+
*/
|
|
2274
|
+
function _rowEditsTargetOnlyCreatedRows(code) {
|
|
2275
|
+
const [updates, deletes, creates] = ["update", "delete", "create"].map((verb) => _mutationCallSites(code, verb));
|
|
2276
|
+
if (!updates || !deletes || !creates) return false;
|
|
2277
|
+
const sites = [...updates, ...deletes];
|
|
2278
|
+
if (sites.length === 0) return false;
|
|
2279
|
+
const created = new Set();
|
|
2280
|
+
for (const site of creates) {
|
|
2281
|
+
const before = code.slice(Math.max(0, site - 200), site);
|
|
2282
|
+
const bound = /(?<![\w$.])([A-Za-z_$][\w$]*)\s*=\s*await\s+(?:[\w$]+\s*\.\s*)?[\w$]+\s*$/.exec(before);
|
|
2283
|
+
if (bound && _boundOnlyByCreate(code, bound[1])) created.add(bound[1]);
|
|
2284
|
+
}
|
|
2285
|
+
return sites.every((open) => {
|
|
2286
|
+
const target = /^\s*([A-Za-z_$][\w$]*)\s*\??\.\s*id\s*[,)]/.exec(code.slice(open + 1));
|
|
2287
|
+
return Boolean(target) && created.has(target[1]);
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
// One declaration, assigned only by that create (a `let row; try { row =
|
|
2292
|
+
// await create(…) }` too). Any other binding of the name, such as a
|
|
2293
|
+
// `.map((row) =>` parameter or a destructure, could be a listed row.
|
|
2294
|
+
function _boundOnlyByCreate(code, name) {
|
|
2295
|
+
const n = name.replace(/\$/g, "\\$");
|
|
2296
|
+
const count = (re) => (code.match(re) || []).length;
|
|
2297
|
+
const emptyDeclaration = new RegExp(`\\blet\\s+${n}\\s*(?:=\\s*(?:null|undefined)\\s*)?[;,]`);
|
|
2298
|
+
return (
|
|
2299
|
+
count(new RegExp(`\\b(?:const|let|var)\\s+${n}(?![\\w$])`, "g")) === 1 &&
|
|
2300
|
+
count(new RegExp(`(?<![\\w$.])${n}\\s*=(?![=>])`, "g")) ===
|
|
2301
|
+
1 + count(new RegExp(`\\blet\\s+${n}\\s*=\\s*(?:null|undefined)\\b`, "g")) &&
|
|
2302
|
+
(count(new RegExp(`\\bconst\\s+${n}\\s*=\\s*await\\b`, "g")) === 1 || emptyDeclaration.test(code)) &&
|
|
2303
|
+
count(new RegExp(`(?<![\\w$.])${n}\\s*(?:=>|[-+*/%&|^?]{1,3}=)`, "g")) === 0 &&
|
|
2304
|
+
count(new RegExp(`\\bfor\\s*\\(\\s*${n}\\s+(?:of|in)\\b`, "g")) === 0 &&
|
|
2305
|
+
count(new RegExp(`[({\\[,:]\\s*(?:\\.\\.\\.)?${n}\\s*[,)}\\]]`, "g")) === 0
|
|
2306
|
+
);
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
/**
|
|
2310
|
+
* Index of the `(` of each call the widget makes to `verb` on a
|
|
2311
|
+
* useDatastoreMutation() result: `verb(` through its destructured local, or
|
|
2312
|
+
* `name.verb(` on a named mutation object. Null when a local cannot be read.
|
|
2313
|
+
*/
|
|
2314
|
+
function _mutationCallSites(code, verb) {
|
|
2315
|
+
const callees = [];
|
|
2316
|
+
for (const call of _mutationHookCalls(code)) {
|
|
2317
|
+
if (!call.destructured) {
|
|
2318
|
+
callees.push(`(?<![\\w$])${call.name.replace(/\$/g, "\\$")}\\s*\\.\\s*${verb}`);
|
|
2319
|
+
continue;
|
|
2320
|
+
}
|
|
2321
|
+
for (const entry of call.destructured.split(",")) {
|
|
2322
|
+
const [key, local = key] = entry.split(":").map((part) => part.trim());
|
|
2323
|
+
if (key !== verb) continue;
|
|
2324
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(local)) return null;
|
|
2325
|
+
callees.push(`(?<![\\w$.])${local.replace(/\$/g, "\\$")}`);
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
if (callees.length === 0) return [];
|
|
2329
|
+
return [...code.matchAll(new RegExp(`(?:${callees.join("|")})\\s*\\(`, "g"))].map(
|
|
2330
|
+
(m) => m.index + m[0].length - 1,
|
|
2331
|
+
);
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2264
2334
|
// The useDatastoreMutation() call whose update or delete the widget uses,
|
|
2265
2335
|
// either as `m.update(` / `m.delete(` or destructured `{ update, delete }`.
|
|
2266
2336
|
function _rowMutationCall(code) {
|
|
@@ -2309,7 +2379,9 @@ function _mutationHookCalls(code) {
|
|
|
2309
2379
|
tails.set(close, _MUTATION_TAIL_RE.test(code) ? _MUTATION_TAIL_RE.lastIndex : -1);
|
|
2310
2380
|
}
|
|
2311
2381
|
if (tails.get(close) !== -1) {
|
|
2312
|
-
|
|
2382
|
+
// The run from an enclosing body brace holds its statements too.
|
|
2383
|
+
const open = code.lastIndexOf("{", close);
|
|
2384
|
+
destructured = { index: open, destructured: code.slice(open + 1, close) };
|
|
2313
2385
|
break;
|
|
2314
2386
|
}
|
|
2315
2387
|
}
|
package/package.json
CHANGED